java.lang.Object
org.codelibs.jcifs.smb1.SmbRandomAccessFile
- All Implemented Interfaces:
DataInput,DataOutput
This class provides random access to files stored on an SMB/CIFS network resource.
It implements the DataInput and DataOutput interfaces for reading and writing primitive
Java data types to the file.
-
Constructor Summary
ConstructorsConstructorDescriptionSmbRandomAccessFile(String url, String mode, int shareAccess) Constructs an SmbRandomAccessFile with the specified URL, mode, and share access flags.SmbRandomAccessFile(SmbFile file, String mode) Constructs an SmbRandomAccessFile from an existing SmbFile with the specified access mode. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the file and releases any system resources associated with it.longReturns the current position of the file pointer.longlength()Returns the length of the file.intread()Reads a single byte from the file at the current file pointer position.intread(byte[] b) Reads bytes from the file into the specified byte array.intread(byte[] b, int off, int len) Reads up to len bytes from the file into the specified byte array.final booleanfinal bytereadByte()final charreadChar()final doublefinal floatfinal voidreadFully(byte[] b) final voidreadFully(byte[] b, int off, int len) final intreadInt()final StringreadLine()final longreadLong()final shortfinal intfinal intfinal StringreadUTF()voidseek(long pos) Sets the file pointer to the specified position.voidsetLength(long newLength) Sets the length of the file.intskipBytes(int n) voidwrite(byte[] b) voidwrite(byte[] b, int off, int len) voidwrite(int b) final voidwriteBoolean(boolean v) final voidwriteByte(int v) final voidwriteBytes(String s) final voidwriteChar(int v) final voidwriteChars(String s) final voidwriteDouble(double v) final voidwriteFloat(float v) final voidwriteInt(int v) final voidwriteLong(long v) final voidwriteShort(int v) final void
-
Constructor Details
-
SmbRandomAccessFile
public SmbRandomAccessFile(String url, String mode, int shareAccess) throws SmbException, MalformedURLException, UnknownHostException Constructs an SmbRandomAccessFile with the specified URL, mode, and share access flags.- Parameters:
url- the SMB URL of the file to accessmode- the access mode ("r" for read-only, "rw" for read-write)shareAccess- the share access flags for file sharing- Throws:
SmbException- if an SMB error occursMalformedURLException- if the URL is malformedUnknownHostException- if the host cannot be resolved
-
SmbRandomAccessFile
public SmbRandomAccessFile(SmbFile file, String mode) throws SmbException, MalformedURLException, UnknownHostException Constructs an SmbRandomAccessFile from an existing SmbFile with the specified access mode.- Parameters:
file- the SmbFile to accessmode- the access mode ("r" for read-only, "rw" for read-write)- Throws:
SmbException- if an SMB error occursMalformedURLException- if the URL is malformedUnknownHostException- if the host cannot be resolved
-
-
Method Details
-
read
Reads a single byte from the file at the current file pointer position.- Returns:
- the byte read as an integer (0-255), or -1 if end of file is reached
- Throws:
SmbException- if an I/O error occurs
-
read
Reads bytes from the file into the specified byte array.- Parameters:
b- the byte array to read data into- Returns:
- the number of bytes read, or -1 if end of file is reached
- Throws:
SmbException- if an I/O error occurs
-
read
Reads up to len bytes from the file into the specified byte array.- Parameters:
b- the byte array to read data intooff- the offset in the array at which to start storing byteslen- the maximum number of bytes to read- Returns:
- the number of bytes read, or -1 if end of file is reached
- Throws:
SmbException- if an I/O error occurs
-
readFully
- Specified by:
readFullyin interfaceDataInput- Throws:
SmbException
-
readFully
- Specified by:
readFullyin interfaceDataInput- Throws:
SmbException
-
skipBytes
- Specified by:
skipBytesin interfaceDataInput- Throws:
SmbException
-
write
- Specified by:
writein interfaceDataOutput- Throws:
SmbException
-
write
- Specified by:
writein interfaceDataOutput- Throws:
SmbException
-
write
- Specified by:
writein interfaceDataOutput- Throws:
SmbException
-
getFilePointer
Returns the current position of the file pointer.- Returns:
- the current file pointer position
- Throws:
SmbException- if an I/O error occurs
-
seek
Sets the file pointer to the specified position.- Parameters:
pos- the new file pointer position- Throws:
SmbException- if an I/O error occurs
-
length
Returns the length of the file.- Returns:
- the file length in bytes
- Throws:
SmbException- if an I/O error occurs
-
setLength
Sets the length of the file. The file will be truncated or extended as necessary.- Parameters:
newLength- the new file length in bytes- Throws:
SmbException- if an I/O error occurs
-
close
Closes the file and releases any system resources associated with it.- Throws:
SmbException- if an I/O error occurs
-
readBoolean
- Specified by:
readBooleanin interfaceDataInput- Throws:
SmbException
-
readByte
- Specified by:
readBytein interfaceDataInput- Throws:
SmbException
-
readUnsignedByte
- Specified by:
readUnsignedBytein interfaceDataInput- Throws:
SmbException
-
readShort
- Specified by:
readShortin interfaceDataInput- Throws:
SmbException
-
readUnsignedShort
- Specified by:
readUnsignedShortin interfaceDataInput- Throws:
SmbException
-
readChar
- Specified by:
readCharin interfaceDataInput- Throws:
SmbException
-
readInt
- Specified by:
readIntin interfaceDataInput- Throws:
SmbException
-
readLong
- Specified by:
readLongin interfaceDataInput- Throws:
SmbException
-
readFloat
- Specified by:
readFloatin interfaceDataInput- Throws:
SmbException
-
readDouble
- Specified by:
readDoublein interfaceDataInput- Throws:
SmbException
-
readLine
- Specified by:
readLinein interfaceDataInput- Throws:
SmbException
-
readUTF
- Specified by:
readUTFin interfaceDataInput- Throws:
SmbException
-
writeBoolean
- Specified by:
writeBooleanin interfaceDataOutput- Throws:
SmbException
-
writeByte
- Specified by:
writeBytein interfaceDataOutput- Throws:
SmbException
-
writeShort
- Specified by:
writeShortin interfaceDataOutput- Throws:
SmbException
-
writeChar
- Specified by:
writeCharin interfaceDataOutput- Throws:
SmbException
-
writeInt
- Specified by:
writeIntin interfaceDataOutput- Throws:
SmbException
-
writeLong
- Specified by:
writeLongin interfaceDataOutput- Throws:
SmbException
-
writeFloat
- Specified by:
writeFloatin interfaceDataOutput- Throws:
SmbException
-
writeDouble
- Specified by:
writeDoublein interfaceDataOutput- Throws:
SmbException
-
writeBytes
- Specified by:
writeBytesin interfaceDataOutput- Throws:
SmbException
-
writeChars
- Specified by:
writeCharsin interfaceDataOutput- Throws:
SmbException
-
writeUTF
- Specified by:
writeUTFin interfaceDataOutput- Throws:
SmbException
-