public abstract class AbstractIpp
extends java.lang.Object
implements java.io.Externalizable
IppRequest and
IppResponse which encapsulates the common code of both classes.
An operation request or response is defined in RFC-2910:
----------------------------------------------- | version-number | 2 bytes - required ----------------------------------------------- | operation-id (request) | | or | 2 bytes - required | status-code (response) | ----------------------------------------------- | request-id | 4 bytes - required ----------------------------------------------- | attribute-group | n bytes - 0 or more ----------------------------------------------- | end-of-attributes-tag | 1 byte - required ----------------------------------------------- | data | q bytes - optional -----------------------------------------------
| Modifier and Type | Class and Description |
|---|---|
static class |
AbstractIpp.Version
Container for the version information.
|
| Modifier and Type | Field and Description |
|---|---|
protected static AbstractIpp.Version |
DEFAULT_VERSION
The actual supported version is 2.
|
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractIpp()
This constructor is needed for the
Externalizable interface. |
|
AbstractIpp(AbstractIpp.Version version,
short opCode,
int requestId,
java.util.List<AttributeGroup> groups)
Instantiates a new IPP request or response with no data.
|
|
AbstractIpp(AbstractIpp.Version version,
short opCode,
int requestId,
java.util.List<AttributeGroup> groups,
byte[] data)
Instantiates a new IPP request or response.
|
protected |
AbstractIpp(byte[] bytes)
Instantiates a new IPP request or responsel from the given bytes.
|
|
AbstractIpp(java.nio.ByteBuffer bytes)
Instantiates a new IPP request or response from the given bytes.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addAttributeGroup(AttributeGroup group)
Adds the given group.
|
boolean |
equals(java.lang.Object obj)
The binary representation of this class is used to compare to request
or respone objects.
|
Attribute |
getAttribute(java.lang.String name)
Gets the attribute with the given name.
|
AttributeGroup |
getAttributeGroup(DelimiterTags tag)
Returns all attributes of the given delimiter-tag.
|
java.util.List<AttributeGroup> |
getAttributeGroups()
The fourth field is the "attribute-group" field, and it occurs 0 or
more times.
|
java.util.List<Attribute> |
getAttributes()
Gets a collected list of all attributes of the attribute-groups.
|
byte[] |
getData()
Returns the data part of the request.
|
int |
getJobId()
Returns the job-id of the request or response.
|
JobState |
getJobState()
Returns the job-state of the request or response.
|
java.lang.String |
getJobStateMessage()
Returns the job-state-message of the request or response.
|
JobStateReasons |
getJobStateReasons()
Returns the job-state-reason of the request or response.
|
java.net.URI |
getJobURI()
Returns the job-uri of the request or response.
|
long |
getLength()
Calculates the size of the request or response.
|
short |
getOpCode()
Returns the 2nd part (byte 2-3) with the operation-id or status-code.
|
protected abstract java.lang.String |
getOpCodeAsString()
Returns the 2nd part (byte 2-3) with the operation-id or status-code as
string.
|
java.util.List<Attribute> |
getOperationAttributes()
Gets a collected list of all operation attributes.
|
java.net.URI |
getPrinterURI()
Gets the URI of the printer from the attributes.
|
int |
getRequestId()
Returns the 3rd part (byte 4-7) of the request which
contains the request-id.
|
AbstractIpp.Version |
getVersion()
Gets the first part (byte 0-1) with the supported IPP version.
|
boolean |
hasAttribute(java.lang.String name)
Checks the attribute with the given name.
|
boolean |
hasData()
The data part of the request can be empty.
|
int |
hashCode() |
void |
readExternal(java.io.ObjectInput in)
The object implements the readExternal method to restore its
contents by reading the byte array and use this array to build up
an IPP request or response.
|
void |
recordTo(java.nio.file.Path logDir)
This method allows you to record a IPP package into a file.
|
static void |
recordTo(java.nio.file.Path logDir,
byte[] bytes,
java.lang.String name)
This method is public because it is used also by other methods.
|
void |
setAttribute(Attribute attr,
DelimiterTags groupTag)
Sets the attribute into the group defined by the groupTag.
|
void |
setAttribute(java.lang.String name,
byte[] value)
Sets the attribute with the given name.
|
void |
setAttributesCharset(java.nio.charset.Charset charset)
Sets the attributes-charset attribute.
|
void |
setAttributesNaturalLanguage(java.util.Locale locale)
Sets the attributes-natural-language attribute.
|
void |
setData(byte[] data)
Sets the data part of the request or response.
|
void |
setJobAttribute(Attribute attr)
Sets the job attribute.
|
void |
setJobId(int id)
Sets the job-id.
|
void |
setJobState(JobState state)
Sets the job-state.
|
void |
setJobStateMessage(java.lang.String msg)
Sets the job-state-message.
|
void |
setJobStateReasons(JobStateReasons reason)
Sets the job-state-rease.
|
void |
setJobURI(java.net.URI uri)
Sets the job-uri.
|
void |
setOpCode(short opCode)
Sets the 2nd part (byte 2-3) with the new operation-id or status-code.
|
void |
setOperationAttribute(Attribute attr)
Sets the operation attribute.
|
void |
setPrinterURI(java.net.URI printerURI)
Sets the printer-uri attribute.
|
void |
setRequestId(int id)
Sets the request-id.
|
void |
setRequestingUserName(java.lang.String username)
Sets the requesting-user-name attribute.
|
byte[] |
toByteArray()
Converts the IppResponse to a byte array as described in RFC-2910.
|
java.lang.String |
toLongString()
Puts all attribute information into the resulting string.
|
java.lang.String |
toShortString()
Provides a shorter version with only the main elements and
attributes.
|
java.lang.String |
toString()
With this toString() implementation we want to provide the most
important values which are useful for logging and debugging.
|
void |
validate()
Validates an request.
|
void |
writeExternal(java.io.ObjectOutput out)
The object implements the writeExternal method to save its contents
by storing it as byte array.
|
protected static final AbstractIpp.Version DEFAULT_VERSION
protected AbstractIpp()
Externalizable interface.protected AbstractIpp(byte[] bytes)
bytes - the bytes of the IPP requestpublic AbstractIpp(java.nio.ByteBuffer bytes)
bytes - the bytes of the IPP requestpublic AbstractIpp(AbstractIpp.Version version, short opCode, int requestId, java.util.List<AttributeGroup> groups)
version - the versionopCode - the code for operation-id or status-coderequestId - the request idgroups - the attribute groupspublic AbstractIpp(AbstractIpp.Version version, short opCode, int requestId, java.util.List<AttributeGroup> groups, byte[] data)
version - the versionopCode - the code for operation-id or status-coderequestId - the request idgroups - the attribute groupsdata - the datapublic void recordTo(java.nio.file.Path logDir)
logDir - the directory where the file is storedpublic static void recordTo(java.nio.file.Path logDir,
byte[] bytes,
java.lang.String name)
logDir - logging directorybytes - data to be recordedname - suffix, which is used as filenamepublic AbstractIpp.Version getVersion()
public void setOpCode(short opCode)
opCode - e.g.0x0000 for status-code 'successful_ok'public short getOpCode()
protected abstract java.lang.String getOpCodeAsString()
public int getRequestId()
public void setRequestId(int id)
id - the new request-idpublic int getJobId()
public void setJobId(int id)
id - the new job-idpublic JobState getJobState()
public void setJobState(JobState state)
state - the new job-statepublic JobStateReasons getJobStateReasons()
public void setJobStateReasons(JobStateReasons reason)
reason - the new job-state-reasonpublic java.lang.String getJobStateMessage()
public void setJobStateMessage(java.lang.String msg)
msg - the new messagepublic java.net.URI getJobURI()
public void setJobURI(java.net.URI uri)
uri - the new job-uripublic java.util.List<AttributeGroup> getAttributeGroups()
public void addAttributeGroup(AttributeGroup group)
group - the grouppublic AttributeGroup getAttributeGroup(DelimiterTags tag)
tag - the delimiter-tagpublic java.util.List<Attribute> getAttributes()
public void setAttribute(java.lang.String name,
byte[] value)
name - name of the attributevalue - byte values of the attributesetAttribute(Attribute, DelimiterTags)public void setAttribute(Attribute attr, DelimiterTags groupTag)
attr - the attributegroupTag - defines the attribute-group where the attribute is insertedpublic Attribute getAttribute(java.lang.String name)
IllegalArgumentException will be thrown.name - name of the attributepublic boolean hasAttribute(java.lang.String name)
name - name of the attributepublic void setOperationAttribute(Attribute attr)
attr - attributepublic void setJobAttribute(Attribute attr)
attr - attributepublic java.util.List<Attribute> getOperationAttributes()
public java.net.URI getPrinterURI()
public void setPrinterURI(java.net.URI printerURI)
printerURI - the printer uripublic void setAttributesCharset(java.nio.charset.Charset charset)
charset - e.g. UTF_8public void setAttributesNaturalLanguage(java.util.Locale locale)
locale - e.g. GERMANYpublic void setRequestingUserName(java.lang.String username)
username - user namepublic void setData(byte[] data)
data - new datapublic byte[] getData()
public boolean hasData()
public java.lang.String toString()
toString in class java.lang.Objectpublic java.lang.String toShortString()
public java.lang.String toLongString()
public byte[] toByteArray()
----------------------------------------------- | version-number | 2 bytes - required ----------------------------------------------- | operation-id or status-code | 2 bytes - required ----------------------------------------------- | request-id | 4 bytes - required ----------------------------------------------- | attribute-group | n bytes - 0 or more ----------------------------------------------- | end-of-attributes-tag | 1 byte - required ----------------------------------------------- | data | q bytes - optional -----------------------------------------------
public long getLength()
public void writeExternal(java.io.ObjectOutput out)
throws java.io.IOException
writeExternal in interface java.io.Externalizableout - the stream to write the object tojava.io.IOException - Includes any I/O exceptions that may occurpublic void readExternal(java.io.ObjectInput in)
throws java.io.IOException
readExternal in interface java.io.Externalizablein - the stream to read data from in order to restore the objectjava.io.IOException - if I/O errors occurpublic void validate()
ValidationException
will be thrown.public boolean equals(java.lang.Object obj)
equals in class java.lang.Objectobj - the other response or requestpublic int hashCode()
hashCode in class java.lang.ObjectCopyright © 2018–2020. All rights reserved.