Package com.oss.util

Class ASN1PrintWriter

All Implemented Interfaces:
Closeable, Flushable, Appendable, AutoCloseable

public class ASN1PrintWriter extends PrintWriter
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 2.0
  • 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

      public ASN1PrintWriter(OutputStream out)
      Create a new ASN1PrintWriter from an existing OutputStream without automatic line flushing.
      Parameters:
      out - an output stream.
    • ASN1PrintWriter

      public ASN1PrintWriter(OutputStream out, boolean autoFlush)
      Create a new ASN1PrintWriter from an existing OutputStream.
      Parameters:
      out - an output stream.
      autoFlush - a boolean; if true, the println() method will flush the output buffer.
    • ASN1PrintWriter

      public ASN1PrintWriter(Writer out)
      Create a new ASN1PrintWriter without automatic line flushing.
      Parameters:
      out - a character-output stream.
    • ASN1PrintWriter

      public ASN1PrintWriter(Writer out, boolean autoFlush)
      Create a new ASN1PrintWriter.
      Parameters:
      out - a character-output stream.
      autoFlush - a boolean; if true, the println() 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 the ASN1PrintWriter 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 that ASN1PrintWriter should set the error indicator and abort the printing if the value contains an error. One can use the checkError() method to check the error state of the stream and the getLastError() 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

      public void print(AbstractData value)
      Print the instance of AbstractData in ASN.1 value notation format.
      Parameters:
      value - the instance of AbstractData to print.
    • print

      public void print(Object obj)
      Overrides the method of the superclass to handle the obj that is the instance of the AbstractData in a special way.
      Overrides:
      print in class PrintWriter
      Parameters:
      obj - the instance of AbstractData to print.
    • println

      public void println(Object obj)
      Overrides the method of the superclass to handle the obj that is the instance of the AbstractData in a special way.
      Overrides:
      println in class PrintWriter
      Parameters:
      obj - the instance of AbstractData to print.
    • getLastError

      public String 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 class PrintWriter
      Returns:
      true if the print stream has encountered an error, either on the underlying output stream or during a format conversion.