Package com.oss.util
Class ASN1PrintWriter
java.lang.Object
java.io.Writer
java.io.PrintWriter
com.oss.util.ASN1PrintWriter
- All Implemented Interfaces:
Closeable
,Flushable
,Appendable
,AutoCloseable
This utility class is the extended version of the
java.io.PrintWriter
that has the ability to print the
instance of AbstractData
in the ASN.1 value notation
format.- Since:
- ASN.1/Java 6.2
-
Constructor Summary
ConstructorsConstructorDescriptionThe default constructor.Create a new ASN1PrintWriter from an existingOutputStream
without automatic line flushing.ASN1PrintWriter
(OutputStream out, boolean autoFlush) Create a new ASN1PrintWriter from an existingOutputStream
.ASN1PrintWriter
(Writer out) Create a new ASN1PrintWriter without automatic line flushing.ASN1PrintWriter
(Writer out, boolean autoFlush) Create a new ASN1PrintWriter. -
Method Summary
Modifier and TypeMethodDescriptionboolean
Flushes the stream if it's not closed and checks its error state.void
Clears the last error that occurred when printing the value notation.void
Specifies thatASN1PrintWriter
should set the error indicator and abort the printing if the value contains an error.void
Specify that the value notation for complex values is printed on a single line.void
Specify that the value is printed as an ASN.1 value notation.void
Specify that DEFAULT values for absent components are not printed.void
Specifies that theASN1PrintWriter
should print the value even if the value contains some errors.void
Specify that the value notation for complex values is printed on multiple lines.void
Specify that the value is printed as an ASN.1 value assignment.void
Specify that components with DEFAULT values are always present in the output even if the components are absent in the it's parent's value.int
Get current setting of the indent width.Get information about the last error that occurred when printing the value notation.int
Get current setting of the truncation limit.boolean
Indicates how errors in the value are handled.boolean
Get current setting of multi-line printing.boolean
Indicates whether the value is printed as a value assignment.boolean
Indicates whether DEFAULT values should be included into the output even if were not explicitly specified.void
print
(AbstractData value) Print the instance ofAbstractData
in ASN.1 value notation format.void
Overrides the method of the superclass to handle theobj
that is the instance of theAbstractData
in a special way.void
Overrides the method of the superclass to handle theobj
that is the instance of theAbstractData
in a special way.void
setIndentWidth
(int indentWidth) Set the width of one indent level.void
setTruncationLimit
(int limit) Set the truncation limit.Methods inherited from class java.io.PrintWriter
append, append, append, close, flush, format, format, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, write, write, write, write, write
Methods inherited from class java.io.Writer
nullWriter
-
Constructor Details
-
ASN1PrintWriter
public ASN1PrintWriter()The default constructor. Sets formatting properties to default values and directs the output to the System.out. The default formatting properties are:- the truncation limit is set to 35;
- the indent width is set to 2;
- multi-line output is enabled;
- the value is printed in the format of the ASN.1 value assignment (both left-hand and right-hand are printed);
- the debugging is enabled (the printing continues if the value being printed contains some errors).
-
ASN1PrintWriter
Create a new ASN1PrintWriter from an existingOutputStream
without automatic line flushing.- Parameters:
out
- an output stream.
-
ASN1PrintWriter
Create a new ASN1PrintWriter from an existingOutputStream
.- Parameters:
out
- an output stream.autoFlush
- aboolean
; if true, theprintln()
method will flush the output buffer.
-
ASN1PrintWriter
Create a new ASN1PrintWriter without automatic line flushing.- Parameters:
out
- a character-output stream.
-
ASN1PrintWriter
Create a new ASN1PrintWriter.- Parameters:
out
- a character-output stream.autoFlush
- aboolean
; if true, theprintln()
method will flush the output buffer.
-
-
Method Details
-
setTruncationLimit
public void setTruncationLimit(int limit) Set the truncation limit. Zero limit means that the lengthy values are never truncated (are printed as is).- Parameters:
limit
- the value of truncation limit.
-
getTruncationLimit
public int getTruncationLimit()Get current setting of the truncation limit. Zero limit means that the truncation is disabled.- Returns:
- the setting of the truncation limit.
-
setIndentWidth
public void setIndentWidth(int indentWidth) Set the width of one indent level. For better readability, components nested in the value are printed with indentation.- Parameters:
indentWidth
- the width of one indentation level.
-
getIndentWidth
public int getIndentWidth()Get current setting of the indent width.- Returns:
- the setting of the indent width.
-
enableMultilinePrinting
public void enableMultilinePrinting()Specify that the value notation for complex values is printed on multiple lines. Child components are indented to the right by the number of print positions specified by the "indent width" setting. For example:value MyType ::= { a "Some string", b 100 }
-
disableMultilinePrinting
public void disableMultilinePrinting()Specify that the value notation for complex values is printed on a single line. For example:value MyType ::= { a "Some string", b 100 }
-
isMultilinePrintingEnabled
public boolean isMultilinePrintingEnabled()Get current setting of multi-line printing.- Returns:
- true if this instance of
ASN1PrintWriter
is set to print the value notation on multiple lines.
-
enablePrintingAsValueAssignment
public void enablePrintingAsValueAssignment()Specify that the value is printed as an ASN.1 value assignment. The format of an ASN.1 value assignment is the value name followed by the type name and the value notation:name Type ::= valueNotation
. For example:a A ::= {1 2 3 4 5}
-
disablePrintingAsValueAssignment
public void disablePrintingAsValueAssignment()Specify that the value is printed as an ASN.1 value notation. In this case the left-hand of the value assignment containing the value name and the type name is omitted. For example:{1 2 3 4 5}
-
isPrintingAsValueAssignmentEnabled
public boolean isPrintingAsValueAssignmentEnabled()Indicates whether the value is printed as a value assignment.- Returns:
- true if this instance of
ASN1PrintWriter
is set to print the value as the ASN.1 value assignment.
-
enablePrintingOfImpliedValues
public void enablePrintingOfImpliedValues()Specify that components with DEFAULT values are always present in the output even if the components are absent in the it's parent's value. -
disablePrintingOfImpliedValues
public void disablePrintingOfImpliedValues()Specify that DEFAULT values for absent components are not printed. -
isPrintingOfImpliedValuesEnabled
public boolean isPrintingOfImpliedValuesEnabled()Indicates whether DEFAULT values should be included into the output even if were not explicitly specified.- Returns:
- true if DEFAULT values should be printed.
-
enableDebugging
public void enableDebugging()Specifies that theASN1PrintWriter
should print the value even if the value contains some errors. Errors are reported in the output as ASN.1 comments. For example:MyType a = new MyType(new IA5String(null), 100); dataPrinter.enableDebugging(); dataPrinter.println(a); The output: ----------- value A ::= { a -- java.lang.NullPointerException --, b 100 }
-
disableDebugging
public void disableDebugging()Specifies thatASN1PrintWriter
should set the error indicator and abort the printing if the value contains an error. One can use thecheckError()
method to check the error state of the stream and thegetLastError()
method to retrieve the information about the last error encountered. For example:MyType a = new MyType(new IA5String(null), 100); dataPrinter.disableDebugging(); dataPrinter.println(a); if (dataPrinter.checkError()) dataPrinter.println("Error: " + dataPrinter.getErrorMessage()); The output: ----------- value A ::= { a } Error: com.oss.asn1printer.DataPrinterException: P0128S: Unexpected exception; check field 'a' (type: IA5String) of PDU 'A'
-
isDebuggingEnabled
public boolean isDebuggingEnabled()Indicates how errors in the value are handled.- Returns:
- true if this instance of
ASN1PrintWriter
is set to continue after the error in the value is detected.
-
print
Print the instance ofAbstractData
in ASN.1 value notation format.- Parameters:
value
- the instance ofAbstractData
to print.
-
print
Overrides the method of the superclass to handle theobj
that is the instance of theAbstractData
in a special way.- Overrides:
print
in classPrintWriter
- Parameters:
obj
- the instance ofAbstractData
to print.
-
println
Overrides the method of the superclass to handle theobj
that is the instance of theAbstractData
in a special way.- Overrides:
println
in classPrintWriter
- Parameters:
obj
- the instance ofAbstractData
to print.
-
getLastError
Get information about the last error that occurred when printing the value notation.- Returns:
- the error message for the last error or null.
-
clearLastError
public void clearLastError()Clears the last error that occurred when printing the value notation. -
checkError
public boolean checkError()Flushes the stream if it's not closed and checks its error state.- Overrides:
checkError
in classPrintWriter
- Returns:
true
if the print stream has encountered an error, either on the underlying output stream or during a format conversion.
-