Search in sources :

Example 1 with File

use of com.hierynomus.smbj.share.File in project iaf by ibissource.

the class Samba2FileSystem method moveFile.

@Override
public String moveFile(String f, String destinationFolder, boolean createFolder) throws FileSystemException {
    try (File file = getFile(f, AccessMask.GENERIC_ALL, SMB2CreateDisposition.FILE_OPEN)) {
        String destination = toFile(destinationFolder, f);
        file.rename(destination, false);
        return destination;
    }
}
Also used : File(com.hierynomus.smbj.share.File)

Example 2 with File

use of com.hierynomus.smbj.share.File in project iaf by ibissource.

the class Samba2FileSystem method appendFile.

@Override
public OutputStream appendFile(String f) throws FileSystemException, IOException {
    final File file = getFile(f, AccessMask.FILE_APPEND_DATA, SMB2CreateDisposition.FILE_OPEN_IF);
    OutputStream out = file.getOutputStream();
    FilterOutputStream fos = new FilterOutputStream(out) {

        boolean isOpen = true;

        @Override
        public void close() throws IOException {
            if (isOpen) {
                super.close();
                isOpen = false;
            }
            file.close();
        }
    };
    return fos;
}
Also used : FilterOutputStream(java.io.FilterOutputStream) OutputStream(java.io.OutputStream) FilterOutputStream(java.io.FilterOutputStream) File(com.hierynomus.smbj.share.File)

Example 3 with File

use of com.hierynomus.smbj.share.File in project iaf by ibissource.

the class Samba2FileSystem method createFile.

@Override
public OutputStream createFile(String f) throws FileSystemException, IOException {
    Set<AccessMask> accessMask = new HashSet<AccessMask>(EnumSet.of(AccessMask.FILE_ADD_FILE));
    Set<SMB2CreateOptions> createOptions = new HashSet<SMB2CreateOptions>(EnumSet.of(SMB2CreateOptions.FILE_NON_DIRECTORY_FILE, SMB2CreateOptions.FILE_WRITE_THROUGH));
    final File file = diskShare.openFile(f, accessMask, null, SMB2ShareAccess.ALL, SMB2CreateDisposition.FILE_OVERWRITE_IF, createOptions);
    OutputStream out = file.getOutputStream();
    FilterOutputStream fos = new FilterOutputStream(out) {

        boolean isOpen = true;

        @Override
        public void close() throws IOException {
            if (isOpen) {
                super.close();
                isOpen = false;
            }
            file.close();
        }
    };
    return fos;
}
Also used : FilterOutputStream(java.io.FilterOutputStream) OutputStream(java.io.OutputStream) SMB2CreateOptions(com.hierynomus.mssmb2.SMB2CreateOptions) AccessMask(com.hierynomus.msdtyp.AccessMask) FilterOutputStream(java.io.FilterOutputStream) File(com.hierynomus.smbj.share.File) HashSet(java.util.HashSet)

Example 4 with File

use of com.hierynomus.smbj.share.File in project iaf by ibissource.

the class Samba2FileSystemTestHelper method getFile.

private File getFile(String filename, AccessMask accessMask, SMB2CreateDisposition createDisposition) {
    Set<SMB2ShareAccess> shareAccess = new HashSet<SMB2ShareAccess>();
    shareAccess.addAll(SMB2ShareAccess.ALL);
    Set<SMB2CreateOptions> createOptions = new HashSet<SMB2CreateOptions>();
    createOptions.add(SMB2CreateOptions.FILE_WRITE_THROUGH);
    Set<AccessMask> accessMaskSet = new HashSet<AccessMask>();
    accessMaskSet.add(accessMask);
    File file;
    file = diskShare.openFile(filename, accessMaskSet, null, shareAccess, createDisposition, createOptions);
    return file;
}
Also used : SMB2CreateOptions(com.hierynomus.mssmb2.SMB2CreateOptions) SMB2ShareAccess(com.hierynomus.mssmb2.SMB2ShareAccess) AccessMask(com.hierynomus.msdtyp.AccessMask) File(com.hierynomus.smbj.share.File) HashSet(java.util.HashSet)

Example 5 with File

use of com.hierynomus.smbj.share.File in project iaf by ibissource.

the class Samba2FileSystemTestHelper method _createFile.

@Override
public OutputStream _createFile(String folder, String filename) throws Exception {
    Set<AccessMask> accessMask = new HashSet<AccessMask>(EnumSet.of(AccessMask.FILE_ADD_FILE));
    Set<SMB2CreateOptions> createOptions = new HashSet<SMB2CreateOptions>(EnumSet.of(SMB2CreateOptions.FILE_NON_DIRECTORY_FILE, SMB2CreateOptions.FILE_WRITE_THROUGH));
    final File file = diskShare.openFile(filename, accessMask, null, SMB2ShareAccess.ALL, SMB2CreateDisposition.FILE_OVERWRITE_IF, createOptions);
    OutputStream out = file.getOutputStream();
    FilterOutputStream fos = new FilterOutputStream(out) {

        boolean isOpen = true;

        @Override
        public void close() throws IOException {
            if (isOpen) {
                super.close();
                isOpen = false;
            }
            file.close();
        }
    };
    return fos;
}
Also used : OutputStream(java.io.OutputStream) FilterOutputStream(java.io.FilterOutputStream) SMB2CreateOptions(com.hierynomus.mssmb2.SMB2CreateOptions) AccessMask(com.hierynomus.msdtyp.AccessMask) FilterOutputStream(java.io.FilterOutputStream) File(com.hierynomus.smbj.share.File) HashSet(java.util.HashSet)

Aggregations

File (com.hierynomus.smbj.share.File)7 AccessMask (com.hierynomus.msdtyp.AccessMask)4 SMB2CreateOptions (com.hierynomus.mssmb2.SMB2CreateOptions)4 HashSet (java.util.HashSet)4 FilterOutputStream (java.io.FilterOutputStream)3 OutputStream (java.io.OutputStream)3 SMB2ShareAccess (com.hierynomus.mssmb2.SMB2ShareAccess)2 FilterInputStream (java.io.FilterInputStream)1 InputStream (java.io.InputStream)1