public class UserSpace
extends java.lang.Object
implements java.io.Serializable
Usage note: By default, the UserSpace class will make use of two different host servers.
For performance reasons, the File Server will be used for read() and write() requests, and
the Remote Command Host Server will be used for create() and other requests.
This behavior can be changed with the setMustUseProgramCall()
method.
Similarly, when running directly on IBM i, by default the UserSpace class will call internal
API's and commands on-thread when possible, bypassing the Remote Command Host Server.
This behavior can be changed with the setMustUseSockets()
method.
As a performance optimization, when running directly on IBM i, it is possible to use native
methods to access the user space from the current job. To enable this support, use the
setMustUseNativeMethods()
method.
For applications that access user spaces located in QTEMP, users are strongly advised to keep everything in the same job, by calling setMustUseProgramCall(true) and setMustUseSockets(true), since different jobs have different QTEMP libraries.
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DOMAIN_DEFAULT
Constant representing the default domain for the user space.
|
static java.lang.String |
DOMAIN_SYSTEM
Constant indicating the domain for the user space is *SYSTEM.
|
static java.lang.String |
DOMAIN_USER
Constant indicating the domain for the user space is *USER.
|
static int |
FORCE_ASYNCHRONOUS
Force to auxiliary storage option that allows changes to be forced asynchronously.
|
static int |
FORCE_NONE
Force to auxiliary storage option that does not allow changes to be forced.
|
static int |
FORCE_SYNCHRONOUS
Force to auxiliary storage option that allows changes to be forced synchronously.
|
Constructor and Description |
---|
UserSpace()
Constructs a UserSpace object.
|
UserSpace(AS400 system,
java.lang.String path)
Constructs a UserSpace object.
|
Modifier and Type | Method and Description |
---|---|
void |
addPropertyChangeListener(java.beans.PropertyChangeListener listener)
Adds a listener to be notified when the value of any bound property is changed.
|
void |
addUserSpaceListener(UserSpaceListener listener)
Adds a listener to be notified when a UserSpaceEvent is fired.
|
void |
addVetoableChangeListener(java.beans.VetoableChangeListener listener)
Adds a listener to be notified when the value of any constrained property is changed.
|
void |
close()
Closes the user space and releases any system resources associated with the stream.
|
void |
create(int length,
boolean replace,
java.lang.String extendedAttribute,
byte initialValue,
java.lang.String textDescription,
java.lang.String authority)
Creates the user space.
|
void |
create(java.lang.String domain,
int length,
boolean replace,
java.lang.String extendedAttribute,
byte initialValue,
java.lang.String textDescription,
java.lang.String authority)
Creates the user space.
|
void |
delete()
Deletes the user space.
|
boolean |
exists()
Determines if the user space exists.
|
byte |
getInitialValue()
Returns the initial value used for filling in the user space during creation and extension.
|
int |
getLength()
Returns the size (in bytes) of the user space.
|
java.lang.String |
getName()
Returns the user space name.
|
java.lang.String |
getPath()
Returns the integrated file system path name of the object represented by the user space.
|
AS400 |
getSystem()
Returns the system object for this user space.
|
boolean |
isAutoExtendible()
Indicates if the user space is auto extendible.
|
boolean |
isMustUseNativeMethods()
Indicates if the native methods will be used internally to perform user space read and write requests.
|
boolean |
isMustUseProgramCall()
Indicates if the Toolbox ProgramCall class will be used internally to perform user space read and write requests.
|
boolean |
isMustUseSockets()
Indicates whether sockets must be used when internally calling programs and commands.
|
int |
read(byte[] dataBuffer,
int userSpaceOffset)
Reads up to dataBuffer.length bytes from the user space beginning at userSpaceOffset into dataBuffer.
|
int |
read(byte[] dataBuffer,
int userSpaceOffset,
int dataOffset,
int length)
Reads up to length bytes from the user space beginning at userSpaceOffset into dataBuffer beginning at dataOffset.
|
java.lang.String |
read(int userSpaceOffset,
int length)
Returns a string from the user space beginning at userSpaceOffset.
|
void |
removePropertyChangeListener(java.beans.PropertyChangeListener listener)
Removes this listener from being notified when a bound property changes.
|
void |
removeUserSpaceListener(UserSpaceListener listener)
Removes a listener from the UserSpace listeners list.
|
void |
removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
Removes this listener from being notified when a constrained property changes.
|
void |
setAutoExtendible(boolean autoExtendibility)
Sets the auto extend attribute if possible.
|
void |
setInitialValue(byte initialValue)
Sets the initial value to be used during user space creation or extension.
|
void |
setLength(int length)
Sets the size (in bytes) of the user space.
|
void |
setMustUseNativeMethods(boolean useNativeMethods)
Specifies whether native methods are used by the current to perform user space read and write operations.
|
void |
setMustUseProgramCall(boolean useProgramCall)
Specifies the API set that is used to perform user space read and write operations.
|
void |
setMustUseSockets(boolean mustUseSockets)
Sets this object to using sockets.
|
void |
setPath(java.lang.String path)
Sets the path for the user space.
|
void |
setSystem(AS400 system)
Sets the system object for the user space.
|
void |
write(byte[] dataBuffer,
int userSpaceOffset)
Writes up to dataBuffer.length bytes from dataBuffer into the user space beginning at userSpaceOffset.
|
void |
write(byte[] dataBuffer,
int userSpaceOffset,
int dataOffset,
int length)
Writes up to length bytes from dataBuffer beginning at dataOffset into the user space beginning at userSpaceOffset.
|
void |
write(byte[] dataBuffer,
int userSpaceOffset,
int dataOffset,
int length,
int forceAuxiliary)
Writes up to length bytes from dataBuffer beginning at dataOffset into the user space beginning at userSpaceOffset.
|
void |
write(java.lang.String data,
int userSpaceOffset)
Writes a string into the user space beginning at userSpaceOffset.
|
public static final int FORCE_ASYNCHRONOUS
public static final int FORCE_NONE
public static final int FORCE_SYNCHRONOUS
public static final java.lang.String DOMAIN_DEFAULT
public static final java.lang.String DOMAIN_USER
public static final java.lang.String DOMAIN_SYSTEM
public UserSpace()
public UserSpace(AS400 system, java.lang.String path)
system
- The system that contains the user space.path
- The fully qualified integrated file system path name to the user space.public void addPropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- The listener object.public void addUserSpaceListener(UserSpaceListener listener)
listener
- The listener object.public void addVetoableChangeListener(java.beans.VetoableChangeListener listener)
listener
- The listener object.public void close() throws java.io.IOException
java.io.IOException
- If an error occurs while communicating with the system.delete()
public void create(int length, boolean replace, java.lang.String extendedAttribute, byte initialValue, java.lang.String textDescription, java.lang.String authority) throws AS400SecurityException, ErrorCompletingRequestException, java.lang.InterruptedException, java.io.IOException, ObjectDoesNotExistException
length
- The initial size (in bytes) of the user space. Valid values are 1 through 16,776,704. User spaces with lengths of 16,773,120 or less will be created with optimum space alignment. These user spaces can not be resized to greater than 16,773,120 bytes. For performance, lengths of 16,773,120 or less are recommended.replace
- The value indicating if an existing user space is to be replaced.extendedAttribute
- The user-defined extended attribute of the user space. This string must be 10 characters or less.initialValue
- The value used in creation and extension.textDescription
- The text describing the user space. This string must be 50 characters or less.authority
- The public authority for the user space. This string must be 10 characters or less. Valid values are:
AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.lang.InterruptedException
- If this thread is interrupted.java.io.IOException
- If an error occurs while communicating with the system.ObjectDoesNotExistException
- If the object does not exist on the system.public void create(java.lang.String domain, int length, boolean replace, java.lang.String extendedAttribute, byte initialValue, java.lang.String textDescription, java.lang.String authority) throws AS400SecurityException, ErrorCompletingRequestException, java.lang.InterruptedException, java.io.IOException, ObjectDoesNotExistException
domain
- The domain into which the user space is created. Valid value are:
length
- The initial size (in bytes) of the user space. Valid values are 1 through 16,776,704. User spaces with lengths of 16,773,120 or less will be created with optimum space alignment. These user spaces can not be resized to greater than 16,773,120 bytes. For performance, lengths of 16,773,120 or less are recommended.replace
- The value indicating if an existing user space is to be replaced.extendedAttribute
- The user-defined extended attribute of the user space. This string must be 10 characters or less.initialValue
- The value used in creation and extension.textDescription
- The text describing the user space. This string must be 50 characters or less.authority
- The public authority for the user space. This string must be 10 characters or less. Valid values are:
AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.lang.InterruptedException
- If this thread is interrupted.java.io.IOException
- If an error occurs while communicating with the system.ObjectDoesNotExistException
- If the object does not exist on the system.public void delete() throws AS400SecurityException, ErrorCompletingRequestException, java.lang.InterruptedException, java.io.IOException, ObjectDoesNotExistException
AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.lang.InterruptedException
- If this thread is interrupted.java.io.IOException
- If an error occurs while communicating with the system.ObjectDoesNotExistException
- If the object does not exist on the system.public boolean exists() throws AS400SecurityException, ErrorCompletingRequestException, java.lang.InterruptedException, java.io.IOException
AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.lang.InterruptedException
- If this thread is interrupted.java.io.IOException
- If an error occurs while communicating with the system.public byte getInitialValue() throws AS400SecurityException, ErrorCompletingRequestException, java.lang.InterruptedException, java.io.IOException, ObjectDoesNotExistException
AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.lang.InterruptedException
- If this thread is interrupted.java.io.IOException
- If an error occurs while communicating with the system.ObjectDoesNotExistException
- If the object does not exist on the system.public int getLength() throws AS400SecurityException, ErrorCompletingRequestException, java.lang.InterruptedException, java.io.IOException, ObjectDoesNotExistException
AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.lang.InterruptedException
- If this thread is interrupted.java.io.IOException
- If an error occurs while communicating with the system.ObjectDoesNotExistException
- If the object does not exist on the system.public java.lang.String getName()
public java.lang.String getPath()
public AS400 getSystem()
public boolean isAutoExtendible() throws AS400SecurityException, ErrorCompletingRequestException, java.lang.InterruptedException, java.io.IOException, ObjectDoesNotExistException
AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.lang.InterruptedException
- If this thread is interrupted.java.io.IOException
- If an error occurs while communicating with the system.ObjectDoesNotExistException
- If the object does not exist on the system.public boolean isMustUseProgramCall()
setMustUseProgramCall(boolean)
public boolean isMustUseNativeMethods()
setMustUseNativeMethods(boolean)
public int read(byte[] dataBuffer, int userSpaceOffset) throws AS400SecurityException, ErrorCompletingRequestException, java.lang.InterruptedException, java.io.IOException, ObjectDoesNotExistException
dataBuffer
- The buffer to fill with data. Buffer.length() bytes will be read from the user space.userSpaceOffset
- The offset in the user space from which to start reading.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.lang.InterruptedException
- If this thread is interrupted.java.io.IOException
- If an error occurs while communicating with the system.ObjectDoesNotExistException
- If the object does not exist on the system.public int read(byte[] dataBuffer, int userSpaceOffset, int dataOffset, int length) throws AS400SecurityException, ErrorCompletingRequestException, java.lang.InterruptedException, java.io.IOException, ObjectDoesNotExistException
dataBuffer
- The buffer to fill with data.userSpaceOffset
- The offset in the user space from which to start reading.dataOffset
- The starting offset in the data buffer for the results of the read.length
- The number of bytes to read.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.lang.InterruptedException
- If this thread is interrupted.java.io.IOException
- If an error occurs while communicating with the system.ObjectDoesNotExistException
- If the object does not exist on the system.public java.lang.String read(int userSpaceOffset, int length) throws AS400SecurityException, ErrorCompletingRequestException, java.lang.InterruptedException, java.io.IOException, ObjectDoesNotExistException
userSpaceOffset
- The offset in the user space from which to start reading.length
- The number of bytes to read.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.lang.InterruptedException
- If this thread is interrupted.java.io.IOException
- If an error occurs while communicating with the system.ObjectDoesNotExistException
- If the object does not exist on the system.public void removePropertyChangeListener(java.beans.PropertyChangeListener listener)
listener
- The listener object.public void removeUserSpaceListener(UserSpaceListener listener)
listener
- The listener object.public void removeVetoableChangeListener(java.beans.VetoableChangeListener listener)
listener
- The listener object.public void setAutoExtendible(boolean autoExtendibility) throws AS400SecurityException, ErrorCompletingRequestException, java.lang.InterruptedException, java.io.IOException, ObjectDoesNotExistException
autoExtendibility
- The attribute for user space auto extendibility.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.lang.InterruptedException
- If this thread is interrupted.java.io.IOException
- If an error occurs while communicating with the system.ObjectDoesNotExistException
- If the object does not exist on the system.public void setInitialValue(byte initialValue) throws AS400SecurityException, ErrorCompletingRequestException, java.lang.InterruptedException, java.io.IOException, ObjectDoesNotExistException
initialValue
- The new initial value used during future extensions. For best performance, set to zero.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.lang.InterruptedException
- If this thread is interrupted.java.io.IOException
- If an error occurs while communicating with the system.ObjectDoesNotExistException
- If the object does not exist on the system.public void setLength(int length) throws AS400SecurityException, ErrorCompletingRequestException, java.lang.InterruptedException, java.io.IOException, ObjectDoesNotExistException
length
- The new size (in bytes) of the user space. Valid values are 1 through 16,776,704. User spaces with lengths of 16,773,120 or less, created with optimum space alignment, can not be resized to greater than 16,773,120 bytes. For performance, lengths of 16,773,120 or less are recommended.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.lang.InterruptedException
- If this thread is interrupted.java.io.IOException
- If an error occurs while communicating with the system.ObjectDoesNotExistException
- If the object does not exist on the system.public void setMustUseProgramCall(boolean useProgramCall)
If accessing user spaces located in QTEMP, it is strongly advised that setMustUseProgramCall(true) be called. In addition, depending on whether subsequent accesses of the user space (such as by program calls) will be run on- or off-thread, you should also call setMustUseSockets(true)
.
This property cannot be reset once a connection has been established.
useProgramCall
- Internally use ProgramCall to perform read and write requests.isMustUseProgramCall()
public void setMustUseNativeMethods(boolean useNativeMethods) throws java.io.UnsupportedEncodingException, java.io.CharConversionException, java.lang.UnsatisfiedLinkError, java.lang.SecurityException
It is not advised to use native methods to access user spaces in QTEMP because toolbox does not provide a method to create a user space in QTEMP of the current job.
The programmer must be aware that no locking occurs when native methods are used to read and write from the user space. If a user space is being used by multiple threads or processes, the values read may reflect a partial operation performed by another thread or process.
useNativeMethods
- Internally use ProgramCall to perform read and write requests.java.io.CharConversionException
java.io.UnsupportedEncodingException
- If the Character Encoding is not supported.java.lang.SecurityException
- If a security error occurs.java.lang.UnsatisfiedLinkError
- If link cannot be satisfied.isMustUseNativeMethods()
public void setPath(java.lang.String path) throws java.beans.PropertyVetoException
path
- The fully qualified integrated file system path name to the user space.java.beans.PropertyVetoException
- If the change is vetoed.public void setSystem(AS400 system) throws java.beans.PropertyVetoException
system
- The system that contains the user space.java.beans.PropertyVetoException
- If the change is vetoed.public void write(byte[] dataBuffer, int userSpaceOffset) throws AS400SecurityException, ErrorCompletingRequestException, java.lang.InterruptedException, java.io.IOException, ObjectDoesNotExistException
dataBuffer
- The data buffer to be written to the user space.userSpaceOffset
- The position in the user space to start writing.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.lang.InterruptedException
- If this thread is interrupted.java.io.IOException
- If an error occurs while communicating with the system.ObjectDoesNotExistException
- If the object does not exist on the system.public void write(byte[] dataBuffer, int userSpaceOffset, int dataOffset, int length) throws AS400SecurityException, ErrorCompletingRequestException, java.lang.InterruptedException, java.io.IOException, ObjectDoesNotExistException
dataBuffer
- The data buffer to be written to the user space.userSpaceOffset
- The position in the user space to start writing.dataOffset
- The position in the write data buffer from which to start copying.length
- The length (in bytes) of data to be written.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.lang.InterruptedException
- If this thread is interrupted.java.io.IOException
- If an error occurs while communicating with the system.ObjectDoesNotExistException
- If the object does not exist on the system.public void write(byte[] dataBuffer, int userSpaceOffset, int dataOffset, int length, int forceAuxiliary) throws AS400SecurityException, ErrorCompletingRequestException, java.lang.InterruptedException, java.io.IOException, ObjectDoesNotExistException
dataBuffer
- The data buffer to be written to the user space.userSpaceOffset
- The position in the user space to start writing.dataOffset
- The position in the write data buffer from which to start copying.length
- The length (in bytes) of data to be written.forceAuxiliary
- The method of forcing changes made to the user space to auxiliary storage. Valid values are:
AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.lang.InterruptedException
- If this thread is interrupted.java.io.IOException
- If an error occurs while communicating with the system.ObjectDoesNotExistException
- If the object does not exist on the system.public void write(java.lang.String data, int userSpaceOffset) throws AS400SecurityException, ErrorCompletingRequestException, java.lang.InterruptedException, java.io.IOException, ObjectDoesNotExistException
data
- The data buffer to be written to the user space.userSpaceOffset
- The position in the user space to start writing.AS400SecurityException
- If a security or authority error occurs.ErrorCompletingRequestException
- If an error occurs before the request is completed.java.lang.InterruptedException
- If this thread is interrupted.java.io.IOException
- If an error occurs while communicating with the system.ObjectDoesNotExistException
- If the object does not exist on the system.public void setMustUseSockets(boolean mustUseSockets)
Note: This method has no effect if the Java application is running remotely, that is, not running directly on an IBM i system. When running remotely, the Toolbox submits all program and command calls via sockets, regardless of the setting of this property.
This property cannot be reset once a connection has been established.
mustUseSockets
- true to use sockets; false otherwise.isMustUseSockets()
,
CommandCall.setThreadSafe(Boolean)
,
ProgramCall.setThreadSafe(boolean)
public boolean isMustUseSockets()
setMustUseSockets(boolean)