com.hierynomus.smbj.share.File Java Examples
The following examples show how to use
com.hierynomus.smbj.share.File.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: Samba2FileSystem.java From iaf with Apache License 2.0 | 8 votes |
@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; }
Example #2
Source File: SMBJController.java From DanDanPlayForAndroid with MIT License | 6 votes |
@Override public long getFileLength(String fileName) { String filePath = getPathNotShare(fileName); try { File file = openFile(diskShare, filePath); FileStandardInformation standardInfo = file.getFileInformation(FileStandardInformation.class); return standardInfo.getEndOfFile(); } catch (Exception e) { e.printStackTrace(); } return 0; }
Example #3
Source File: SMBJController.java From DanDanPlayForAndroid with MIT License | 6 votes |
/** * get smb file, just need reed permission * * @param share share * @param filePath file path not share name * @return smb file */ private File openFile(DiskShare share, String filePath) { return share.openFile(filePath, EnumSet.of(AccessMask.FILE_READ_DATA), null, SMB2ShareAccess.ALL, FILE_OPEN, null); }
Example #4
Source File: SMBJ_RPCController.java From DanDanPlayForAndroid with MIT License | 6 votes |
@Override public InputStream getFileInputStream(String fileName) { String filePath = getPathNotShare(fileName); try { File file = openFile(diskShare, filePath); inputStream = file.getInputStream(); } catch (Exception e) { e.printStackTrace(); } return inputStream; }
Example #5
Source File: SMBJ_RPCController.java From DanDanPlayForAndroid with MIT License | 6 votes |
@Override public long getFileLength(String fileName) { String filePath = getPathNotShare(fileName); try { File file = openFile(diskShare, filePath); FileStandardInformation standardInfo = file.getFileInformation(FileStandardInformation.class); return standardInfo.getEndOfFile(); } catch (Exception e) { e.printStackTrace(); } return 0; }
Example #6
Source File: SMBJ_RPCController.java From DanDanPlayForAndroid with MIT License | 6 votes |
/** * get smb file, just need reed permission * * @param share share * @param filePath file path not share name * @return smb file */ private File openFile(DiskShare share, String filePath) { return share.openFile(filePath, EnumSet.of(AccessMask.FILE_READ_DATA), null, SMB2ShareAccess.ALL, FILE_OPEN, null); }
Example #7
Source File: SMBJController.java From DanDanPlayForAndroid with MIT License | 6 votes |
@Override public InputStream getFileInputStream(String fileName) { String filePath = getPathNotShare(fileName); try { File file = openFile(diskShare, filePath); inputStream = file.getInputStream(); return inputStream; } catch (Exception e) { e.printStackTrace(); } return null; }
Example #8
Source File: SMB2Utils.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 6 votes |
private static OutputStream getOutputStream(final PooledSMB2Connection connection, String path, boolean append) throws IOException { try { DiskShare share = connection.getShare(); Set<AccessMask> accessMask = append ? EnumSet.of(AccessMask.FILE_APPEND_DATA) : EnumSet.of(AccessMask.FILE_WRITE_DATA); SMB2CreateDisposition createDisposition = append ? SMB2CreateDisposition.FILE_OPEN_IF : SMB2CreateDisposition.FILE_OVERWRITE_IF; final com.hierynomus.smbj.share.File file = openFile(share, path, accessMask, createDisposition); OutputStream os = append ? new AppendOutputStream(file) : file.getOutputStream(); if (append) { // add buffering, AppendOutputStream is slow os = new BufferedOutputStream(os, connection.getWriteBufferSize()); } os = new CloseOnceOutputStream(os) { @Override protected void doClose() throws IOException { try { super.doClose(); } finally { FileUtils.closeAll(file, connection); } } }; return os; } catch (Throwable t) { connection.returnToPool(); throw ExceptionUtils.getIOException(t); } }
Example #9
Source File: Samba2FileSystem.java From iaf with Apache License 2.0 | 6 votes |
@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; }
Example #10
Source File: Samba2FileSystem.java From iaf with Apache License 2.0 | 6 votes |
@Override public InputStream readFile(String filename) throws FileSystemException, IOException { final File file = getFile(filename, AccessMask.GENERIC_READ, SMB2CreateDisposition.FILE_OPEN); InputStream is = file.getInputStream(); FilterInputStream fis = new FilterInputStream(is) { boolean isOpen = true; @Override public void close() throws IOException { if(isOpen) { super.close(); isOpen=false; } file.close(); } }; return fis; }
Example #11
Source File: Samba2FileSystem.java From iaf with Apache License 2.0 | 5 votes |
@Override public long getFileSize(String f) throws FileSystemException { long size; if (isFolder(f)) { try (Directory dir = getFolder(f, AccessMask.FILE_READ_ATTRIBUTES, SMB2CreateDisposition.FILE_OPEN)) { size = dir.getFileInformation().getStandardInformation().getAllocationSize(); return size; } } else { try (File file = getFile(f, AccessMask.FILE_READ_ATTRIBUTES, SMB2CreateDisposition.FILE_OPEN)) { size = file.getFileInformation().getStandardInformation().getAllocationSize(); return size; } } }
Example #12
Source File: Samba2FileSystem.java From iaf with Apache License 2.0 | 5 votes |
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; }
Example #13
Source File: Samba2FileSystem.java From iaf with Apache License 2.0 | 5 votes |
@Override public String copyFile(String f, String destinationFolder, boolean createFolder) throws FileSystemException { try (File file = getFile(f, AccessMask.GENERIC_ALL, SMB2CreateDisposition.FILE_OPEN)) { String destination = getDestinationFile(f, destinationFolder, createFolder, "copy"); try (File destinationFile = getFile(f, AccessMask.GENERIC_ALL, SMB2CreateDisposition.FILE_OVERWRITE)) { file.remoteCopyTo(destinationFile); } catch (TransportException | BufferException e) { throw new FileSystemException("cannot copy file ["+f+"] to ["+destinationFolder+"]",e); } return destination; } }
Example #14
Source File: Samba2FileSystem.java From iaf with Apache License 2.0 | 5 votes |
@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 = getDestinationFile(f, destinationFolder, createFolder, "move"); file.rename(destination, false); return destination; } }
Example #15
Source File: Samba2FileSystem.java From iaf with Apache License 2.0 | 5 votes |
@Override public String renameFile(String f, String newName, boolean force) throws FileSystemException { try (File file = getFile(f, AccessMask.GENERIC_ALL, SMB2CreateDisposition.FILE_OPEN)) { if (exists(newName) && !force) { throw new FileSystemException("Cannot rename file. Destination file already exists."); } file.rename(newName, force); } return newName; }
Example #16
Source File: SMB2Utils.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 5 votes |
private static InputStream getInputStream(final PooledSMB2Connection connection, String path) throws IOException { try { DiskShare share = connection.getShare(); Set<AccessMask> accessMask = EnumSet.of(AccessMask.FILE_READ_DATA); SMB2CreateDisposition createDisposition = SMB2CreateDisposition.FILE_OPEN; final com.hierynomus.smbj.share.File file = openFile(share, path, accessMask, createDisposition); InputStream is = file.getInputStream(); is = new CloseOnceInputStream(is) { @Override protected void doClose() throws IOException { try { super.doClose(); } finally { FileUtils.closeAll(file, connection); } } }; return is; } catch (Throwable t) { connection.returnToPool(); throw ExceptionUtils.getIOException(t); } }
Example #17
Source File: SMB2Utils.java From CloverETL-Engine with GNU Lesser General Public License v2.1 | 4 votes |
public AppendOutputStream(File file) { this.file = Objects.requireNonNull(file); this.fileOffset = file.getFileInformation(FileStandardInformation.class).getEndOfFile(); }