public class IFSRandomAccessFile
extends java.lang.Object
implements java.io.DataInput, java.io.DataOutput, java.io.Serializable
// Work with /Dir/File on the system eniac. AS400 as400 = new AS400("eniac"); IFSRandomAccessFile file = new IFSRandomAccessFile(as400, "/Dir/File", "rw"); // Determine the file length. long length = file.length(); // Lock the first 11 bytes. IFSKey key = file.lock(0, 11); // Write a string to the file. file.writeChars("Hello world"); // Read the string we just wrote. file.seek(0); String s = file.readLine(); // Close the file. file.close();
Modifier and Type | Field and Description |
---|---|
static int |
FAIL_OR_CREATE
File existence option that indicates that the request is either to fail if the file exists or is to create the file if it does not exist.
|
static int |
OPEN_OR_CREATE
File existence option that indicates that the file is either to be opened if it exists or is to be created if it does not exist.
|
static int |
OPEN_OR_FAIL
File existence option that indicates that the file is either to be opened if it exists or that the request is to fail if the file does not exist.
|
static int |
REPLACE_OR_CREATE
File existence option that indicates that the file is either to be replaced if it exists or is to be created if it does not exist.
|
static int |
REPLACE_OR_FAIL
File existence option that indicates that the file is either to be replaced if it exists or that the request is to fail if the file does not exist.
|
static int |
SHARE_ALL
Share option that allows read and write access by other users.
|
static int |
SHARE_NONE
Share option that does not allow read or write access by other users.
|
static int |
SHARE_READERS
Share option that allows only read access by other users.
|
static int |
SHARE_WRITERS
Share option that allows only write access by other users.
|
Constructor and Description |
---|
IFSRandomAccessFile()
Constructs an IFSRandomAccessFile object.
|
IFSRandomAccessFile(AS400 system,
IFSFile file,
java.lang.String mode,
int shareOption,
int existenceOption)
Deprecated.
Use IFSRandomAccessFile(IFSFile,String,int,int) instead.
|
IFSRandomAccessFile(AS400 system,
java.lang.String name,
java.lang.String mode)
Constructs an IFSRandomAccessFile object.
|
IFSRandomAccessFile(AS400 system,
java.lang.String name,
java.lang.String mode,
int shareOption,
int existenceOption)
Constructs an IFSRandomAccessFile object.
|
IFSRandomAccessFile(IFSFile file,
java.lang.String mode,
int shareOption,
int existenceOption)
Constructs an IFSRandomAccessFile object.
|
Modifier and Type | Method and Description |
---|---|
void |
addFileListener(FileListener listener)
Adds a file listener to receive file events from this IFSRandomAccessFile.
|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a property change listener.
|
void |
addVetoableChangeListener(java.beans.VetoableChangeListener listener)
Adds a vetoable change listener.
|
void |
close()
Closes this random access file stream and releases any system resources
associated with the stream.
|
protected void |
finalize()
Ensures that the stream is closed when there are no more references to it.
|
void |
flush()
Forces any buffered output bytes to be written.
|
int |
getExistenceOption()
Returns the existence option for this object.
|
IFSFileDescriptor |
getFD()
Returns a file descriptor associated with this stream.
|
long |
getFilePointer()
Returns the current offset in this file.
|
java.lang.String |
getPath()
Returns the integrated file system path name of the object represented by
this IFSRandomAccessFile.
|
int |
getShareOption()
Returns the share option for this object.
|
AS400 |
getSystem()
Returns the AS400 system object for this stream.
|
long |
length()
Returns the file length.
|
IFSKey |
lock(int offset,
int length)
Deprecated.
Replaced by
lock(long,long) |
IFSKey |
lock(long offset,
long length)
Places a lock on the file at the specified bytes.
|
int |
read()
Reads the next byte of data from this file.
|
int |
read(byte[] data)
Reads up to data.length bytes of data from this input stream into
data.
|
int |
read(byte[] data,
int dataOffset,
int length)
Reads up to length bytes of data from this input stream into
data, starting at the array offset dataOffset.
|
boolean |
readBoolean()
Reads a boolean from this file.
|
byte |
readByte()
Reads a signed 8-bit value from this file.
|
char |
readChar()
Reads a Unicode character from this file.
|
double |
readDouble()
Reads a double from this file.
|
float |
readFloat()
Reads a float from this file.
|
void |
readFully(byte[] data)
Reads data.length bytes from this file into the byte array.
|
void |
readFully(byte[] data,
int dataOffset,
int length)
Reads exactly length bytes from this file into the byte array.
|
int |
readInt()
Reads a signed 32-bit integer from this file.
|
java.lang.String |
readLine()
Reads the next line of text from this file.
|
long |
readLong()
Reads a signed 64-bit integer from this file.
|
short |
readShort()
Reads a signed 16-bit integer from this file.
|
int |
readUnsignedByte()
Reads an unsigned 8-bit number from this file.
|
int |
readUnsignedShort()
Reads an unsigned 16-bit number from this file.
|
java.lang.String |
readUTF()
Reads in a string from this file.
|
void |
removeFileListener(FileListener listener)
Removes a file listener so that it no longer receives file events from
this IFSRandomAccessFile.
|
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes a property change listener.
|
void |
removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
Removes a vetoable change listener.
|
void |
seek(long position)
Sets the offset, from the beginning of this file, at which the next read
or write occurs.
|
void |
setExistenceOption(int existenceOption)
Sets the existence option.
|
void |
setLength(int length)
Deprecated.
Replaced by
setLength(long) |
void |
setLength(long length)
Sets the length of the file represented by this object.
|
void |
setMode(java.lang.String mode)
Sets the access mode.
|
void |
setPath(java.lang.String path)
Sets the file path.
|
void |
setShareOption(int shareOption)
Sets the share option.
|
void |
setSystem(AS400 system)
Sets the system.
|
int |
skipBytes(int bytesToSkip)
Deprecated.
Replaced by
skipBytes(long) |
long |
skipBytes(long bytesToSkip)
Skips over the next bytesToSkip bytes in the stream.
|
void |
unlock(IFSKey key)
Undoes a lock on this file.
|
void |
write(byte[] data)
Writes data.length bytes of data from the byte array data
to this file output stream.
|
void |
write(byte[] data,
int dataOffset,
int length)
Writes length bytes from the byte array data, starting at dataOffset, to this file.
|
void |
write(int b)
Writes the specified byte to this file.
|
void |
writeBoolean(boolean value)
Writes a boolean to the file as a one-byte value.
|
void |
writeByte(int value)
Writes a byte to the file as a one-byte value.
|
void |
writeBytes(java.lang.String s)
Writes out the string to the file as a sequence of bytes.
|
void |
writeChar(int value)
Writes a char to the file as a two-byte value, high byte first.
|
void |
writeChars(java.lang.String s)
Writes a string to the file as a sequence of characters.
|
void |
writeDouble(double value)
Converts the double argument to a long using the doubleToLongBits method in
class Double, and then writes that long value to the file as an eight-byte
quantity, high-byte first.
|
void |
writeFloat(float value)
Converts the float argument to an int using the floatToIntBits method in
class Float, and then writes that int value to the file as a four-byte
quantity, high-byte first.
|
void |
writeInt(int value)
Writes an int to the file as four bytes, high-byte first.
|
void |
writeLong(long value)
Writes a long to the file as eight bytes, high-byte first.
|
void |
writeShort(int value)
Writes a short to the file as two bytes, high-byte first.
|
void |
writeUTF(java.lang.String s)
Writes out a string to the file using UTF-8 encoding in a
machine-independent manner.
|
public static final int SHARE_ALL
public static final int SHARE_NONE
public static final int SHARE_READERS
public static final int SHARE_WRITERS
public static final int FAIL_OR_CREATE
public static final int OPEN_OR_CREATE
public static final int OPEN_OR_FAIL
public static final int REPLACE_OR_CREATE
public static final int REPLACE_OR_FAIL
public IFSRandomAccessFile()
public IFSRandomAccessFile(AS400 system, java.lang.String name, java.lang.String mode) throws AS400SecurityException, java.io.IOException
system
- The AS400 that contains the file.name
- The file name.mode
- The access mode AS400SecurityException
- If a security or authority error occurs.java.io.IOException
- If an error occurs while communicating with the system.public IFSRandomAccessFile(AS400 system, java.lang.String name, java.lang.String mode, int shareOption, int existenceOption) throws AS400SecurityException, java.io.IOException
system
- The AS400 that contains the file.name
- The file name.mode
- The acess mode shareOption
- Indicates how users can access the file. existenceOption
- Indicates if the file should be created, opened or
if the request should fail based on the existence of the file.
AS400SecurityException
- If a security or authority error occurs.java.io.IOException
- If an error occurs while communicating with the system.public IFSRandomAccessFile(AS400 system, IFSFile file, java.lang.String mode, int shareOption, int existenceOption) throws AS400SecurityException, java.io.IOException
system
- The AS400 that contains the file.file
- The file to access.mode
- The access mode shareOption
- Indicates how other user's can access the file. existenceOption
- Indicates if the file should be created, opened or if the request should fail based on the existence of the file. AS400SecurityException
- If a security or authority error occurs.java.io.IOException
- If an error occurs while communicating with the system.public IFSRandomAccessFile(IFSFile file, java.lang.String mode, int shareOption, int existenceOption) throws AS400SecurityException, java.io.IOException
file
- The file to access.mode
- The access mode shareOption
- Indicates how other user's can access the file. existenceOption
- Indicates if the file should be created, opened or if the request should fail based on the existence of the file. AS400SecurityException
- If a security or authority error occurs.java.io.IOException
- If an error occurs while communicating with the system.public void addFileListener(FileListener listener)
listener
- The file listener.public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- The property change listener to add.public void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
listener
- The vetoable change listener to add.public void close() throws java.io.IOException
java.io.IOException
- If an error occurs while communicating with the system.protected void finalize() throws java.io.IOException
finalize
in class java.lang.Object
java.io.IOException
- If an error occurs while communicating with the system.public void flush() throws java.io.IOException
java.io.IOException
- If an error occurs while communicating with the system.public int getExistenceOption()
public final IFSFileDescriptor getFD() throws java.io.IOException
java.io.IOException
- If an error occurs while communicating with the system.public long getFilePointer() throws java.io.IOException
java.io.IOException
- If an error occurs while communicating with the system.public java.lang.String getPath()
public int getShareOption()
public AS400 getSystem()
public long length() throws java.io.IOException
java.io.IOException
- If an error occurs while communicating with the system.public IFSKey lock(int offset, int length) throws java.io.IOException
lock(long,long)
offset
- The first byte of the file to lock (zero is the first byte).length
- The number of bytes to lock.java.io.IOException
- If an error occurs while communicating with the system.IFSKey
,
unlock(com.ibm.as400.access.IFSKey)
public IFSKey lock(long offset, long length) throws java.io.IOException
offset
- The first byte of the file to lock (zero is the first byte).length
- The number of bytes to lock.java.io.IOException
- If an error occurs while communicating with the system.IFSKey
,
unlock(com.ibm.as400.access.IFSKey)
public int read() throws java.io.IOException
java.io.IOException
- If an error occurs while communicating with the system.public int read(byte[] data) throws java.io.IOException
data
- The buffer into which data is read.java.io.IOException
- If an error occurs while communicating with the system.public int read(byte[] data, int dataOffset, int length) throws java.io.IOException
data
- The buffer into which the data is read.dataOffset
- The start offset of the data in the buffer.length
- The maximum number of bytes to read.java.io.IOException
- If an error occurs while communicating with the system.public final boolean readBoolean() throws java.io.IOException
readBoolean
in interface java.io.DataInput
java.io.IOException
- If an error occurs while communicating with the system.public final byte readByte() throws java.io.IOException
readByte
in interface java.io.DataInput
java.io.IOException
- If an error occurs while communicating with the system.public final char readChar() throws java.io.IOException
readChar
in interface java.io.DataInput
java.io.IOException
- If an error occurs while communicating with the system.public final double readDouble() throws java.io.IOException
readDouble
in interface java.io.DataInput
java.io.IOException
- If an error occurs while communicating with the system.public final float readFloat() throws java.io.IOException
readFloat
in interface java.io.DataInput
java.io.IOException
- If an error occurs while communicating with the system.public final void readFully(byte[] data) throws java.io.IOException
readFully
in interface java.io.DataInput
data
- The buffer into which data is read.java.io.IOException
- If an error occurs while communicating with the system.public final void readFully(byte[] data, int dataOffset, int length) throws java.io.IOException
readFully
in interface java.io.DataInput
data
- The buffer into which data is read.dataOffset
- The start offset in the data buffer.length
- The number of bytes to read.java.io.IOException
- If an error occurs while communicating with the system.public final int readInt() throws java.io.IOException
readInt
in interface java.io.DataInput
java.io.IOException
- If an error occurs while communicating with the system.public final java.lang.String readLine() throws java.io.IOException
readLine
in interface java.io.DataInput
java.io.IOException
- If an error occurs while communicating with the system.public final long readLong() throws java.io.IOException
readLong
in interface java.io.DataInput
java.io.IOException
- If an error occurs while communicating with the system.public final short readShort() throws java.io.IOException
readShort
in interface java.io.DataInput
java.io.IOException
- If an error occurs while communicating with the system.public final int readUnsignedByte() throws java.io.IOException
readUnsignedByte
in interface java.io.DataInput
java.io.IOException
- If an error occurs while communicating with the system.public final int readUnsignedShort() throws java.io.IOException
readUnsignedShort
in interface java.io.DataInput
java.io.IOException
- If an error occurs while communicating with the system.public final java.lang.String readUTF() throws java.io.IOException
readUTF
in interface java.io.DataInput
java.io.IOException
- If an error occurs while communicating with the system.public void removeFileListener(FileListener listener)
listener
- The file listener.public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- The property change listener to remove.public void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
listener
- The vetoable change listener to remove.public void seek(long position) throws java.io.IOException
position
- The absolute position of the file pointer.java.io.IOException
- If an error occurs while communicating with the system.public void setExistenceOption(int existenceOption) throws java.beans.PropertyVetoException
existenceOption
- Indicates if the file should be created, opened or if the request should fail based on the existence of the file. java.beans.PropertyVetoException
- If the change is vetoed.public void setLength(int length) throws java.io.IOException
setLength(long)
length
- The new length, in bytes.java.io.IOException
- If an error occurs while communicating with the system.public void setLength(long length) throws java.io.IOException
length
- The new length, in bytes.java.io.IOException
- If an error occurs while communicating with the system.public void setMode(java.lang.String mode) throws java.beans.PropertyVetoException
mode
- The access mode. java.beans.PropertyVetoException
- If the change is vetoed.public void setPath(java.lang.String path) throws java.beans.PropertyVetoException
path
- The absolute integrated file system path name.java.beans.PropertyVetoException
- If the change is vetoed.public void setShareOption(int shareOption) throws java.beans.PropertyVetoException
shareOption
- Indicates how users can access the file. java.beans.PropertyVetoException
- If the change is vetoed.public void setSystem(AS400 system) throws java.beans.PropertyVetoException
system
- The system object.java.beans.PropertyVetoException
- If the change is vetoed.public int skipBytes(int bytesToSkip) throws java.io.IOException
skipBytes(long)
skipBytes
in interface java.io.DataInput
bytesToSkip
- The number of bytes to skip.java.io.IOException
- If an error occurs while communicating with the system.public long skipBytes(long bytesToSkip) throws java.io.IOException
bytesToSkip
- The number of bytes to skip.java.io.IOException
- If an error occurs while communicating with the system.public void unlock(IFSKey key) throws java.io.IOException
key
- The key for the lock.java.io.IOException
- If an error occurs while communicating with the system.IFSKey
,
lock(int, int)
public void write(int b) throws java.io.IOException
write
in interface java.io.DataOutput
b
- The byte to write.java.io.IOException
- If an error occurs while communicating with the system.public void write(byte[] data) throws java.io.IOException
write
in interface java.io.DataOutput
data
- The data to write.java.io.IOException
- If an error occurs while communicating with the system.public void write(byte[] data, int dataOffset, int length) throws java.io.IOException
write
in interface java.io.DataOutput
data
- The data.dataOffset
- The start offset in the data.length
- The number of bytes to write.java.io.IOException
- If an error occurs while communicating with the system.public final void writeBoolean(boolean value) throws java.io.IOException
writeBoolean
in interface java.io.DataOutput
value
- The value to be written.java.io.IOException
- If an error occurs while communicating with the system.public final void writeByte(int value) throws java.io.IOException
writeByte
in interface java.io.DataOutput
value
- The value to be written as a byte.java.io.IOException
- If an error occurs while communicating with the system.public final void writeBytes(java.lang.String s) throws java.io.IOException
writeBytes
in interface java.io.DataOutput
s
- The bytes to write.java.io.IOException
- If an error occurs while communicating with the system.writeChars(String)
public final void writeChar(int value) throws java.io.IOException
writeChar
in interface java.io.DataOutput
value
- A character value to write.java.io.IOException
- If an error occurs while communicating with the system.public final void writeChars(java.lang.String s) throws java.io.IOException
writeChars
in interface java.io.DataOutput
s
- A String to write.java.io.IOException
- If an error occurs while communicating with the system.public final void writeDouble(double value) throws java.io.IOException
writeDouble
in interface java.io.DataOutput
value
- The value to write.java.io.IOException
- If an error occurs while communicating with the system.public final void writeFloat(float value) throws java.io.IOException
writeFloat
in interface java.io.DataOutput
java.io.IOException
- If an error occurs while communicating with the system.public final void writeInt(int value) throws java.io.IOException
writeInt
in interface java.io.DataOutput
value
- The int to write.java.io.IOException
- If an error occurs while communicating with the system.public final void writeLong(long value) throws java.io.IOException
writeLong
in interface java.io.DataOutput
value
- The value to write.java.io.IOException
- If an error occurs while communicating with the system.public final void writeShort(int value) throws java.io.IOException
writeShort
in interface java.io.DataOutput
value
- The value to write.java.io.IOException
- If an error occurs while communicating with the system.public final void writeUTF(java.lang.String s) throws java.io.IOException
writeUTF
in interface java.io.DataOutput
s
- The string to write.java.io.IOException
- If an error occurs while communicating with the system.