Package com.hierynomus.smbj.share
Class File
- java.lang.Object
-
- com.hierynomus.smbj.share.Open<DiskShare>
-
- com.hierynomus.smbj.share.DiskEntry
-
- com.hierynomus.smbj.share.File
-
- All Implemented Interfaces:
java.io.Closeable
,java.lang.AutoCloseable
public class File extends DiskEntry
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.hierynomus.smbj.share.Open
Open.LockBuilder
-
-
Field Summary
Fields Modifier and Type Field Description private static StatusHandler
COPY_CHUNK_ALLOWED_STATUS_VALUES
private static int
FSCTL_SRV_REQUEST_RESUME_KEY
private SMB2Writer
writer
-
Constructor Summary
Constructors Constructor Description File(SMB2FileId fileId, DiskShare diskShare, SmbPath fileName)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description private static SMB2IoctlResponse
copyChunk(Share share, File target, CopyChunkRequest request)
See [MS-SMB2] 2.2.31.1.1 SRV_COPYCHUNK https://msdn.microsoft.com/en-us/library/cc246546.aspxprivate static java.util.List<CopyChunkRequest.Chunk>
createCopyChunks(long srcOffset, long dstOffset, long length, long maxChunkCount, long maxChunkSize, long maxRequestSize)
Creates the list of copy chunks to copylength
bytes fromsrcOffset
todstOffset
java.io.InputStream
getInputStream()
java.io.InputStream
getInputStream(ProgressListener listener)
java.io.OutputStream
getOutputStream()
java.io.OutputStream
getOutputStream(boolean append)
java.io.OutputStream
getOutputStream(ProgressListener listener)
java.io.OutputStream
getOutputStream(ProgressListener listener, boolean append)
private byte[]
getResumeKey()
See [MS-SMB2] 2.2.32.3 SRV_REQUEST_RESUME_KEY Response https://msdn.microsoft.com/en-us/library/cc246804.aspxint
read(byte[] buffer, long fileOffset)
Read data from this file starting at position fileOffset into the given buffer.int
read(byte[] buffer, long fileOffset, int offset, int length)
Read data from this file starting at position fileOffset into the given buffer.void
read(java.io.OutputStream destStream)
void
read(java.io.OutputStream destStream, ProgressListener progressListener)
long
read(java.nio.ByteBuffer buffer, long fileOffset)
Read data from this file starting at position fileOffset into the givenByteBuffer
.(package private) java.util.concurrent.Future<SMB2ReadResponse>
readAsync(long offset, int length)
void
remoteCopyTo(long offset, File destination, long destinationOffset, long length)
Copies the byte range[offset, length]
of this file to the range[destinationOffset, length]
of the given destination file.void
remoteCopyTo(File destination)
Performs a remote file copy of this file to the given file.private static void
remoteFileCopy(File source, long sourceOffset, File destination, long destinationOffset, long length)
Remote copy logic as described in https://msdn.microsoft.com/en-us/library/cc246475.aspxvoid
setLength(long endOfFile)
The function for truncate or set file length for a filejava.lang.String
toString()
long
write(byte[] buffer, long fileOffset)
Write the data in buffer to this file at position fileOffset.long
write(byte[] buffer, long fileOffset, int offset, int length)
Write the data in buffer to this file at position fileOffset.long
write(ByteChunkProvider provider)
Write all available data from the byte chunk provider to this file.long
write(ByteChunkProvider provider, ProgressListener progressListener)
Write all available data from the byte chunk provider to this file.long
write(java.nio.ByteBuffer buffer, long fileOffset)
Write the data in aByteBuffer
to this file at position fileOffset.java.util.concurrent.Future<java.lang.Long>
writeAsync(byte[] buffer, long fileOffset, int offset, int length)
Write the data Async in buffer to this file at position fileOffset.java.util.concurrent.Future<java.lang.Long>
writeAsync(ByteChunkProvider provider)
Async Write all available data from the byte chunk provider to this file.-
Methods inherited from class com.hierynomus.smbj.share.DiskEntry
closeNoWait, createHardlink, createHardlink, deleteOnClose, equals, flush, getDiskShare, getFileInformation, getFileInformation, getFileName, getPath, getSecurityInformation, getUncPath, hashCode, ioctl, ioctl, ioctl, rename, rename, rename, setFileInformation, setSecurityInformation, setSecurityInformation
-
Methods inherited from class com.hierynomus.smbj.share.Open
close, closeSilently, getFileId, lockRequest, requestLock
-
-
-
-
Field Detail
-
writer
private final SMB2Writer writer
-
FSCTL_SRV_REQUEST_RESUME_KEY
private static final int FSCTL_SRV_REQUEST_RESUME_KEY
- See Also:
- Constant Field Values
-
COPY_CHUNK_ALLOWED_STATUS_VALUES
private static final StatusHandler COPY_CHUNK_ALLOWED_STATUS_VALUES
-
-
Constructor Detail
-
File
File(SMB2FileId fileId, DiskShare diskShare, SmbPath fileName)
-
-
Method Detail
-
write
public long write(byte[] buffer, long fileOffset)
Write the data in buffer to this file at position fileOffset.- Parameters:
buffer
- the data to writefileOffset
- The offset, in bytes, into the file to which the data should be written- Returns:
- the actual number of bytes that was written to the file
-
write
public long write(byte[] buffer, long fileOffset, int offset, int length)
Write the data in buffer to this file at position fileOffset.- Parameters:
buffer
- the data to writefileOffset
- The offset, in bytes, into the file to which the data should be writtenoffset
- the start offset in the datalength
- the number of bytes that are written- Returns:
- the actual number of bytes that was written to the file
-
write
public long write(ByteChunkProvider provider)
Write all available data from the byte chunk provider to this file. The offset in the file to which data is written is determined byByteChunkProvider.getOffset()
.- Parameters:
provider
- the byte chunk provider- Returns:
- the actual number of bytes that was written to the file
-
write
public long write(ByteChunkProvider provider, ProgressListener progressListener)
Write all available data from the byte chunk provider to this file. The offset in the file to which data is written is determined byByteChunkProvider.getOffset()
.- Parameters:
provider
- the byte chunk providerprogressListener
- an optional callback that will be invoked when data has been written to the file- Returns:
- the actual number of bytes that was written to the file
-
writeAsync
public java.util.concurrent.Future<java.lang.Long> writeAsync(byte[] buffer, long fileOffset, int offset, int length)
Write the data Async in buffer to this file at position fileOffset.- Parameters:
buffer
- the data to writefileOffset
- The offset, in bytes, into the file to which the data should be writtenoffset
- the start offset in the datalength
- the number of bytes that are written- Returns:
- A Future containing the total number of bytes written to the remote.
-
writeAsync
public java.util.concurrent.Future<java.lang.Long> writeAsync(ByteChunkProvider provider)
Async Write all available data from the byte chunk provider to this file. The offset in the file to which data is written is determined byByteChunkProvider.getOffset()
.- Parameters:
provider
- the byte chunk provider- Returns:
- A future containing the total number of bytes written to the remote.
-
getOutputStream
public java.io.OutputStream getOutputStream()
-
getOutputStream
public java.io.OutputStream getOutputStream(boolean append)
-
getOutputStream
public java.io.OutputStream getOutputStream(ProgressListener listener)
-
getOutputStream
public java.io.OutputStream getOutputStream(ProgressListener listener, boolean append)
-
read
public int read(byte[] buffer, long fileOffset)
Read data from this file starting at position fileOffset into the given buffer.- Parameters:
buffer
- the buffer to write intofileOffset
- The offset, in bytes, into the file from which the data should be read- Returns:
- the actual number of bytes that were read; or -1 if the end of the file was reached
-
read
public int read(byte[] buffer, long fileOffset, int offset, int length)
Read data from this file starting at position fileOffset into the given buffer.- Parameters:
buffer
- the buffer to write intofileOffset
- The offset, in bytes, into the file from which the data should be readoffset
- the start offset in the buffer at which to write datalength
- the maximum number of bytes to read- Returns:
- the actual number of bytes that were read; or -1 if the end of the file was reached
-
readAsync
java.util.concurrent.Future<SMB2ReadResponse> readAsync(long offset, int length)
-
read
public void read(java.io.OutputStream destStream) throws java.io.IOException
- Throws:
java.io.IOException
-
read
public void read(java.io.OutputStream destStream, ProgressListener progressListener) throws java.io.IOException
- Throws:
java.io.IOException
-
write
public long write(java.nio.ByteBuffer buffer, long fileOffset)
Write the data in aByteBuffer
to this file at position fileOffset.- Parameters:
buffer
- the data to writefileOffset
- The offset, in bytes, into the file to which the data should be written- Returns:
- the actual number of bytes that was written to the file
-
read
public long read(java.nio.ByteBuffer buffer, long fileOffset)
Read data from this file starting at position fileOffset into the givenByteBuffer
.- Parameters:
buffer
- theByteBuffer
to write intofileOffset
- The offset, in bytes, into the file from which the data should be read- Returns:
- the actual number of bytes that were read; or -1 if the end of the file was reached
-
remoteCopyTo
public void remoteCopyTo(File destination) throws Buffer.BufferException, TransportException
Performs a remote file copy of this file to the given file.This method is equivalent to calling
remoteCopyTo(0, destination, 0, sourceFileSize)
.- Parameters:
destination
- the destination file- Throws:
Buffer.BufferException
TransportException
-
remoteCopyTo
public void remoteCopyTo(long offset, File destination, long destinationOffset, long length) throws Buffer.BufferException, TransportException
Copies the byte range[offset, length]
of this file to the range[destinationOffset, length]
of the given destination file.- Parameters:
destination
- the destination file- Throws:
Buffer.BufferException
TransportException
-
remoteFileCopy
private static void remoteFileCopy(File source, long sourceOffset, File destination, long destinationOffset, long length) throws Buffer.BufferException, TransportException
Remote copy logic as described in https://msdn.microsoft.com/en-us/library/cc246475.aspx
-
getResumeKey
private byte[] getResumeKey() throws Buffer.BufferException
See [MS-SMB2] 2.2.32.3 SRV_REQUEST_RESUME_KEY Response https://msdn.microsoft.com/en-us/library/cc246804.aspx- Throws:
Buffer.BufferException
-
createCopyChunks
private static java.util.List<CopyChunkRequest.Chunk> createCopyChunks(long srcOffset, long dstOffset, long length, long maxChunkCount, long maxChunkSize, long maxRequestSize)
Creates the list of copy chunks to copylength
bytes fromsrcOffset
todstOffset
- Parameters:
srcOffset
- the source file offset at which to start readingdstOffset
- the destination file offset at which to start writinglength
- the total number of bytes to copymaxChunkCount
- the maximum number of chunks that may be createmaxChunkSize
- the maximum size of each individual chunkmaxRequestSize
- the maximum total size of all chunks combined- Returns:
- a list of copy chunks
-
copyChunk
private static SMB2IoctlResponse copyChunk(Share share, File target, CopyChunkRequest request)
See [MS-SMB2] 2.2.31.1.1 SRV_COPYCHUNK https://msdn.microsoft.com/en-us/library/cc246546.aspx
-
setLength
public void setLength(long endOfFile) throws SMBApiException
The function for truncate or set file length for a file- Parameters:
endOfFile
- 64-bit signed integer in bytes, MUST be greater than or equal to 0- Throws:
SMBApiException
-
getInputStream
public java.io.InputStream getInputStream()
-
getInputStream
public java.io.InputStream getInputStream(ProgressListener listener)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-