Class SoOutput


  • public class SoOutput
    extends Inventor
    Used to write Open Inventor data files. This class is used for writing Open Inventor data files. It supports both ASCII (default) and binary formats and provides some convenience functions for opening and closing files. See SbFileHelper for more convenience functions. It can write to a buffer in memory as well as to a file. Since Open Inventor 8.1, SoOutput can write compressed data in the lossless Zlib (aka gzip) format. Both ASCII and binary format files may be compressed.

    An instance of SoOutput is automatically created by SoWriteAction and can be queried using the getOutput() method in that class. This is typically the only instance needed. For example:

     SoWriteAction writeAction = new SoWriteAction()  ;
     writeAction.getOutput().openFile( "output.iv" );
     writeAction.apply( root );
     writeAction.getOutput().closeFile();

    Note that file properties (binary, compression, header string, etc) should be set before calling openFile() or setFilePointer().

    File extensions
    The recommended file extension for Open Inventor format files, both ASCII and binary is ".iv". Open Inventor will automatically detect if the file is ASCII or binary based on the file header string. Compressed Open Inventor files may be given the extension ".ivz" for convenience, but it is not required. Open Inventor automatically detects compressed files.

    File Header
    Open Inventor writes a human readable file header as the first line of both ASCII and binary format files. Since Open Inventor 8.0, the default file header looks like this:
    ASCII : "#Inventor V8.0 ascii"
    Binary: "#Inventor V8.0 binary LE"
    The two character code at the end of the binary header indicates if the file was written on a little-endian (LE) or big-endian (BE) machine. The version number string may change again in the future if incompatible changes are made to the file format. You can always query the current default headers using static methods getDefaultASCIIHeader() and getDefaultBinaryHeader().

    All versions of Open Inventor from version 2.1 through version 7.x, wrote the version number string "V2.1" by default and did not append "LE" (or "BE") to the binary header. Open Inventor cannot, in general, load files containing a file header from a newer version. However all versions of Open Inventor can load files written by older versions and can load files containing the V2.1 file header. We recommend always using the default file header because newer versions enable performance enhancing features in the file format. If you need to write a file compatible with older versions, call setHeaderString() with "#Inventor V2.1 ascii" or "#Inventor V2.1 binary".

    See Also:
    SoInput, SoWriteAction, SoTranSender, SbFileHelper
    • Constructor Detail

      • SoOutput

        public SoOutput()
        Constructor. The default SoOutput writes to stdout.
    • Method Detail

      • incrementIndent

        public void incrementIndent()
        Calls incrementIndent((int)1).
      • decrementIndent

        public void decrementIndent()
        Calls decrementIndent((int)1).
      • setFileProperty

        public void setFileProperty​(SoOutput.FileProperties properties)
        Sets a combination of properties for the current file. The function must be called before the output of any data. It can be called before the openFile or setFilePointer functions.

        The default property is DefaultProperty when the SoOutput object is created.

        Since:
        Open Inventor 8.1

      • resetHeaderString

        public void resetHeaderString()
        Resets the header for output files to be the default header.
      • filePuts

        public int filePuts​(java.lang.String name_18589)
        Write a string to the currently open file.
        If the file is compressed the string is compressed on the fly. Returns -1 if no file is currently open. Returns EOF if an error occurs. Returns a non-negative value if successful (same as fputs).

        Since:
        Open Inventor 8.1

      • isBinary

        public boolean isBinary()
        Returns current state of binary flag.
      • isWritingForScaleViz

        public boolean isWritingForScaleViz()
        Returns true if ScaleViz is currently writing data for synchronization.
      • getBufferSize

        public long getBufferSize()
        The total number of bytes allocated to a memory buffer may be larger than the number of bytes written. This returns that total number.
      • setBinary

        public void setBinary​(boolean flag)
        Sets whether output should be ASCII (default) or binary.
      • resetBuffer

        public void resetBuffer()
        Resets buffer for output again. Output starts over at beginning of buffer.
      • openFile

        public boolean openFile​(java.lang.String fileName)
        Opens named file, sets current file to result. This returns false on error.
      • filePutc

        public int filePutc​(int name_18590)
        Write a byte to the currently open file.
        If the file is compressed the byte is compressed on the fly. Returns -1 if no file is currently open. Returns EOF if an error occurs. Returns the byte value specified if successful.

        Since:
        Open Inventor 8.1

      • closeFile

        public void closeFile()
        Closes current file if opened with openFile().
      • setHeaderString

        public void setHeaderString​(java.lang.String str)
        Sets the header for output files. This is useful, for example, if you have a file format that is a superset of the Open Inventor file format and you want Open Inventor to read the files. It is highly recommend that in your new header you simply append to the header of the Open Inventor file format you are extending. For example, if a new file format is based on the Open Inventor 2.1 file format, register a header similar to: "#Inventor V2.1 ascii MY FILE FORMAT EXTENSION". Then all Open Inventor 2.1 applications (and later) can read the file.
      • write

        public void write​(java.lang.String n)
      • incrementIndent

        public void incrementIndent​(int amount)
      • write

        public void write​(int i)
      • write

        public void write​(byte c)
      • write

        public void write​(boolean b)
      • getIndentLevel

        public int getIndentLevel()
      • decrementIndent

        public void decrementIndent​(int amount)
      • indent

        public void indent()
      • getDefaultASCIIHeader

        public static java.lang.String getDefaultASCIIHeader()
        Returns the string representing the default ASCII header.
      • setDoublePrecision

        public void setDoublePrecision​(int precision)
        Sets the precision for writing floating point numbers (type double), i.e. the number of significant digits. Floating point numbers are written using %.xg format, where 'x' is the value of the precision argument.
      • setFloatPrecision

        public void setFloatPrecision​(int precision)
        Sets the precision for writing floating point numbers (type float), i.e. the number of significant digits. Floating point numbers are written using %.xg format, where 'x' is the value of the precision argument.
      • write

        public void write​(double d)
      • flushFile

        public void flushFile()
      • write

        public void write​(long i)
      • write

        public void write​(short s)
      • getDefaultBinaryHeader

        public static java.lang.String getDefaultBinaryHeader()
        Returns the string representing the default binary header.
      • write

        public void write​(float f)