|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.ibm.as400.access.IFSRandomAccessFile
The IFSRandomAccessFile class supports read and write access to integrated file system objects. The position at which the next access occurs can be modified. This class offers methods that allow specified mode access of read-only, write-only, or read-write.
IFSRandomAccessFile objects are capable of generating file events that call the following FileListener methods: fileClosed, fileModified, and fileOpened.
The following example illustrates the use of IFSRandomAccessFile:
// 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();
FileEvent
,
addFileListener(com.ibm.as400.access.FileListener)
,
removeFileListener(com.ibm.as400.access.FileListener)
,
Serialized FormField Summary | |
---|---|
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 Summary | |
---|---|
IFSRandomAccessFile()
Constructs an IFSRandomAccessFile object. |
|
IFSRandomAccessFile(AS400 system,
IFSFile file,
String mode,
int shareOption,
int existenceOption)
Deprecated. Use IFSRandomAccessFile(IFSFile,String,int,int) instead. |
|
IFSRandomAccessFile(AS400 system,
String name,
String mode)
Constructs an IFSRandomAccessFile object. |
|
IFSRandomAccessFile(AS400 system,
String name,
String mode,
int shareOption,
int existenceOption)
Constructs an IFSRandomAccessFile object. |
|
IFSRandomAccessFile(IFSFile file,
String mode,
int shareOption,
int existenceOption)
Constructs an IFSRandomAccessFile object. |
Method Summary | |
---|---|
void |
addFileListener(FileListener listener)
Adds a file listener to receive file events from this IFSRandomAccessFile. |
void |
addPropertyChangeListener(PropertyChangeListener listener)
Adds a property change listener. |
void |
addVetoableChangeListener(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. |
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)
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. |
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. |
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(PropertyChangeListener listener)
Removes a property change listener. |
void |
removeVetoableChangeListener(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)
Sets the length of the file represented by this object. |
void |
setMode(String mode)
Sets the access mode. |
void |
setPath(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)
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(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(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(String s)
Writes out a string to the file using UTF-8 encoding in a machine-independent manner. |
Methods inherited from class java.lang.Object |
---|
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
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
Constructor Detail |
public IFSRandomAccessFile()
public IFSRandomAccessFile(AS400 system, String name, String mode) throws AS400SecurityException, IOException
system
- The AS400 that contains the file.name
- The file name.mode
- The access mode AS400SecurityException
- If a security or authority error occurs.
IOException
- If an error occurs while communicating with the system.public IFSRandomAccessFile(AS400 system, String name, String mode, int shareOption, int existenceOption) throws AS400SecurityException, 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.
IOException
- If an error occurs while communicating with the system.public IFSRandomAccessFile(AS400 system, IFSFile file, String mode, int shareOption, int existenceOption) throws AS400SecurityException, 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.
IOException
- If an error occurs while communicating with the system.public IFSRandomAccessFile(IFSFile file, String mode, int shareOption, int existenceOption) throws AS400SecurityException, 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.
IOException
- If an error occurs while communicating with the system.Method Detail |
public void addFileListener(FileListener listener)
listener
- The file listener.public void addPropertyChangeListener(PropertyChangeListener listener)
listener
- The property change listener to add.public void addVetoableChangeListener(VetoableChangeListener listener)
listener
- The vetoable change listener to add.public void close() throws IOException
IOException
- If an error occurs while communicating with the system.protected void finalize() throws IOException
IOException
- If an error occurs while communicating with the system.public void flush() throws IOException
IOException
- If an error occurs while communicating with the system.public int getExistenceOption()
public final IFSFileDescriptor getFD() throws IOException
IOException
- If an error occurs while communicating with the system.public long getFilePointer() throws IOException
IOException
- If an error occurs while communicating with the system.public String getPath()
public int getShareOption()
public AS400 getSystem()
public long length() throws IOException
IOException
- If an error occurs while communicating with the system.public IFSKey lock(int offset, int length) throws IOException
offset
- The first byte of the file to lock (zero is the first byte).length
- The number of bytes to lock.
IOException
- If an error occurs while communicating with the system.IFSKey
,
unlock(com.ibm.as400.access.IFSKey)
public int read() throws IOException
IOException
- If an error occurs while communicating with the system.public int read(byte[] data) throws IOException
data
- The buffer into which data is read.
IOException
- If an error occurs while communicating with the system.public int read(byte[] data, int dataOffset, int length) throws 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.
IOException
- If an error occurs while communicating with the system.public final boolean readBoolean() throws IOException
readBoolean
in interface DataInput
IOException
- If an error occurs while communicating with the system.public final byte readByte() throws IOException
readByte
in interface DataInput
IOException
- If an error occurs while communicating with the system.public final char readChar() throws IOException
readChar
in interface DataInput
IOException
- If an error occurs while communicating with the system.public final double readDouble() throws IOException
readDouble
in interface DataInput
IOException
- If an error occurs while communicating with the system.public final float readFloat() throws IOException
readFloat
in interface DataInput
IOException
- If an error occurs while communicating with the system.public final void readFully(byte[] data) throws IOException
readFully
in interface DataInput
data
- The buffer into which data is read.
IOException
- If an error occurs while communicating with the system.public final void readFully(byte[] data, int dataOffset, int length) throws IOException
readFully
in interface DataInput
data
- The buffer into which data is read.dataOffset
- The start offset in the data buffer.length
- The number of bytes to read.
IOException
- If an error occurs while communicating with the system.public final int readInt() throws IOException
readInt
in interface DataInput
IOException
- If an error occurs while communicating with the system.public final String readLine() throws IOException
readLine
in interface DataInput
IOException
- If an error occurs while communicating with the system.public final long readLong() throws IOException
readLong
in interface DataInput
IOException
- If an error occurs while communicating with the system.public final short readShort() throws IOException
readShort
in interface DataInput
IOException
- If an error occurs while communicating with the system.public final int readUnsignedByte() throws IOException
readUnsignedByte
in interface DataInput
IOException
- If an error occurs while communicating with the system.public final int readUnsignedShort() throws IOException
readUnsignedShort
in interface DataInput
IOException
- If an error occurs while communicating with the system.public final String readUTF() throws IOException
readUTF
in interface DataInput
IOException
- If an error occurs while communicating with the system.public void removeFileListener(FileListener listener)
listener
- The file listener.public void removePropertyChangeListener(PropertyChangeListener listener)
listener
- The property change listener to remove.public void removeVetoableChangeListener(VetoableChangeListener listener)
listener
- The vetoable change listener to remove.public void seek(long position) throws IOException
position
- The absolute position of the file pointer.
IOException
- If an error occurs while communicating with the system.public void setExistenceOption(int existenceOption) throws PropertyVetoException
existenceOption
- Indicates if the file should be created, opened or if the request should fail based on the existence of the file. PropertyVetoException
- If the change is vetoed.public void setLength(int length) throws IOException
length
- The new length, in bytes.
IOException
- If an error occurs while communicating with the system.public void setMode(String mode) throws PropertyVetoException
mode
- The access mode. PropertyVetoException
- If the change is vetoed.public void setPath(String path) throws PropertyVetoException
path
- The absolute integrated file system path name.
PropertyVetoException
- If the change is vetoed.public void setShareOption(int shareOption) throws PropertyVetoException
shareOption
- Indicates how users can access the file. PropertyVetoException
- If the change is vetoed.public void setSystem(AS400 system) throws PropertyVetoException
system
- The system object.
PropertyVetoException
- If the change is vetoed.public int skipBytes(int bytesToSkip) throws IOException
skipBytes
in interface DataInput
bytesToSkip
- The number of bytes to skip.
IOException
- If an error occurs while communicating with the system.public void unlock(IFSKey key) throws IOException
key
- The key for the lock.
IOException
- If an error occurs while communicating with the system.IFSKey
,
lock(int, int)
public void write(int b) throws IOException
write
in interface DataOutput
b
- The byte to write.
IOException
- If an error occurs while communicating with the system.public void write(byte[] data) throws IOException
write
in interface DataOutput
data
- The data to write.
IOException
- If an error occurs while communicating with the system.public void write(byte[] data, int dataOffset, int length) throws IOException
write
in interface DataOutput
data
- The data.dataOffset
- The start offset in the data.length
- The number of bytes to write.
IOException
- If an error occurs while communicating with the system.public final void writeBoolean(boolean value) throws IOException
writeBoolean
in interface DataOutput
value
- The value to be written.
IOException
- If an error occurs while communicating with the system.public final void writeByte(int value) throws IOException
writeByte
in interface DataOutput
value
- The value to be written as a byte.
IOException
- If an error occurs while communicating with the system.public final void writeBytes(String s) throws IOException
writeBytes
in interface DataOutput
s
- The bytes to write.
IOException
- If an error occurs while communicating with the system.writeChars(String)
public final void writeChar(int value) throws IOException
writeChar
in interface DataOutput
value
- A character value to write.
IOException
- If an error occurs while communicating with the system.public final void writeChars(String s) throws IOException
writeChars
in interface DataOutput
s
- A String to write.
IOException
- If an error occurs while communicating with the system.public final void writeDouble(double value) throws IOException
writeDouble
in interface DataOutput
value
- The value to write.
IOException
- If an error occurs while communicating with the system.public final void writeFloat(float value) throws IOException
writeFloat
in interface DataOutput
IOException
- If an error occurs while communicating with the system.public final void writeInt(int value) throws IOException
writeInt
in interface DataOutput
value
- The int to write.
IOException
- If an error occurs while communicating with the system.public final void writeLong(long value) throws IOException
writeLong
in interface DataOutput
value
- The value to write.
IOException
- If an error occurs while communicating with the system.public final void writeShort(int value) throws IOException
writeShort
in interface DataOutput
value
- The value to write.
IOException
- If an error occurs while communicating with the system.public final void writeUTF(String s) throws IOException
writeUTF
in interface DataOutput
s
- The string to write.
IOException
- If an error occurs while communicating with the system.
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |