Class BinaryStlFacetDefinitionReader

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean hasReadHeader
      True when the header content has been read.
      private java.nio.ByteBuffer header
      Header content.
      private java.io.InputStream in
      Input stream to read from.
      private java.nio.ByteBuffer triangleBuffer
      Buffer used to read triangle definitions.
      private long trianglesRead
      Number of triangles read so far.
      private long triangleTotal
      Total number of triangles declared to be present in the input.
    • Constructor Summary

      Constructors 
      Constructor Description
      BinaryStlFacetDefinitionReader​(java.io.InputStream in)
      Construct a new instance that reads from the given input stream.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void beginRead()
      Read the file header content and triangle count.
      void close()
      Close this instance and release all associated resources.
      private static java.lang.IllegalStateException dataNotAvailable​(java.lang.String name)
      Return an exception stating that data is not available for the file component with the given name.
      private int fill​(java.nio.ByteBuffer buf)
      Fill the buffer with data from the input stream.
      java.nio.ByteBuffer getHeader()
      Get a read-only buffer containing the 80 bytes of the STL header.
      java.lang.String getHeaderAsString()
      Return the header content as a string decoded using the UTF-8 charset.
      java.lang.String getHeaderAsString​(java.nio.charset.Charset charset)
      Return the header content as a string decoded using the given charset.
      long getNumTriangles()
      Get the total number of triangles (i.e.
      BinaryStlFacetDefinition readFacet()
      Return the next facet definition from the input source or null if no more facets are available.
      private BinaryStlFacetDefinition readFacetInternal()
      Internal method to read a single facet from the input.
      private Vector3D readVector​(java.nio.ByteBuffer buf)
      Read a vector from the given byte buffer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • in

        private final java.io.InputStream in
        Input stream to read from.
      • triangleBuffer

        private final java.nio.ByteBuffer triangleBuffer
        Buffer used to read triangle definitions.
      • header

        private java.nio.ByteBuffer header
        Header content.
      • triangleTotal

        private long triangleTotal
        Total number of triangles declared to be present in the input.
      • trianglesRead

        private long trianglesRead
        Number of triangles read so far.
      • hasReadHeader

        private boolean hasReadHeader
        True when the header content has been read.
    • Constructor Detail

      • BinaryStlFacetDefinitionReader

        public BinaryStlFacetDefinitionReader​(java.io.InputStream in)
        Construct a new instance that reads from the given input stream.
        Parameters:
        in - input stream to read from.
    • Method Detail

      • getHeader

        public java.nio.ByteBuffer getHeader()
        Get a read-only buffer containing the 80 bytes of the STL header. The header does not include the 4-byte value indicating the total number of triangles in the STL file.
        Returns:
        the STL header content
        Throws:
        java.io.UncheckedIOException - if an I/O error occurs
      • getHeaderAsString

        public java.lang.String getHeaderAsString()
        Return the header content as a string decoded using the UTF-8 charset. Control characters (such as '\0') are not included in the result.
        Returns:
        the header content decoded as a UTF-8 string
        Throws:
        java.io.UncheckedIOException - if an I/O error occurs
      • getHeaderAsString

        public java.lang.String getHeaderAsString​(java.nio.charset.Charset charset)
        Return the header content as a string decoded using the given charset. Control characters (such as '\0') are not included in the result.
        Parameters:
        charset - charset to decode the header with
        Returns:
        the header content decoded as a string
        Throws:
        java.io.UncheckedIOException - if an I/O error occurs
      • getNumTriangles

        public long getNumTriangles()
        Get the total number of triangles (i.e. facets) declared to be present in the input.
        Returns:
        total number of triangle in the input
        Throws:
        java.io.UncheckedIOException - if an I/O error occurs
      • readFacet

        public BinaryStlFacetDefinition readFacet()
        Return the next facet definition from the input source or null if no more facets are available.
        Specified by:
        readFacet in interface FacetDefinitionReader
        Returns:
        the next facet definition or null if no more facets are available
      • close

        public void close()
        Close this instance and release all associated resources.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface FacetDefinitionReader
      • beginRead

        private void beginRead()
        Read the file header content and triangle count.
        Throws:
        java.lang.IllegalStateException - is a parse error occurs
        java.io.UncheckedIOException - if an I/O error occurs
      • readFacetInternal

        private BinaryStlFacetDefinition readFacetInternal()
        Internal method to read a single facet from the input.
        Returns:
        facet read from the input
      • fill

        private int fill​(java.nio.ByteBuffer buf)
        Fill the buffer with data from the input stream. The buffer is then flipped and made ready for reading.
        Parameters:
        buf - buffer to fill
        Returns:
        number of bytes read
        Throws:
        java.io.UncheckedIOException - if an I/O error occurs
      • readVector

        private Vector3D readVector​(java.nio.ByteBuffer buf)
        Read a vector from the given byte buffer.
        Parameters:
        buf - buffer to read from
        Returns:
        vector containing the next 3 double values from the given buffer
      • dataNotAvailable

        private static java.lang.IllegalStateException dataNotAvailable​(java.lang.String name)
        Return an exception stating that data is not available for the file component with the given name.
        Parameters:
        name - name of the file component missing data
        Returns:
        exception instance