Class StreamUtil


  • public final class StreamUtil
    extends java.lang.Object
    This file is a helper class for internal usage only. Be aware that its API and functionality may be changed in future.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static byte[] escB  
      private static byte[] escF  
      private static byte[] escN  
      private static byte[] escR  
      private static byte[] escT  
      private static int TRANSFER_SIZE  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private StreamUtil()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void copyBytes​(IRandomAccessSource source, long start, long length, java.io.OutputStream output)
      Copy bytes from the RandomAccessSource to OutputStream.
      static ByteBuffer createBufferedEscapedString​(byte[] bytes)  
      static ByteBuffer createBufferedHexedString​(byte[] bytes)  
      static byte[] createEscapedString​(byte[] bytes)
      Escapes a byte array according to the PDF conventions.
      static byte[] inputStreamToArray​(java.io.InputStream stream)
      Reads the full content of a stream and returns them in a byte array
      static void readFully​(java.io.InputStream input, byte[] b, int off, int len)
      Reads len bytes from an input stream.
      static void skip​(java.io.InputStream stream, long size)
      This method is an alternative for the InputStream.skip() -method that doesn't seem to work properly for big values of size .
      static void transferBytes​(RandomAccessFileOrArray input, java.io.OutputStream output)  
      static void transferBytes​(java.io.InputStream input, java.io.OutputStream output)  
      static void writeEscapedString​(java.io.OutputStream outputStream, byte[] bytes)
      Escapes a byte array according to the PDF conventions.
      static void writeHexedString​(java.io.OutputStream outputStream, byte[] bytes)  
      • Methods inherited from class java.lang.Object

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

      • escR

        private static final byte[] escR
      • escN

        private static final byte[] escN
      • escT

        private static final byte[] escT
      • escB

        private static final byte[] escB
      • escF

        private static final byte[] escF
    • Constructor Detail

      • StreamUtil

        private StreamUtil()
    • Method Detail

      • skip

        public static void skip​(java.io.InputStream stream,
                                long size)
                         throws java.io.IOException
        This method is an alternative for the InputStream.skip() -method that doesn't seem to work properly for big values of size .
        Parameters:
        stream - the InputStream
        size - the number of bytes to skip
        Throws:
        java.io.IOException - if an I/O error occurs.
      • createEscapedString

        public static byte[] createEscapedString​(byte[] bytes)
        Escapes a byte array according to the PDF conventions.
        Parameters:
        bytes - the byte array to escape
        Returns:
        an escaped byte array
      • writeEscapedString

        public static void writeEscapedString​(java.io.OutputStream outputStream,
                                              byte[] bytes)
        Escapes a byte array according to the PDF conventions.
        Parameters:
        outputStream - the OutputStream an escaped byte array write to.
        bytes - the byte array to escape.
      • writeHexedString

        public static void writeHexedString​(java.io.OutputStream outputStream,
                                            byte[] bytes)
      • createBufferedEscapedString

        public static ByteBuffer createBufferedEscapedString​(byte[] bytes)
      • createBufferedHexedString

        public static ByteBuffer createBufferedHexedString​(byte[] bytes)
      • transferBytes

        public static void transferBytes​(java.io.InputStream input,
                                         java.io.OutputStream output)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • transferBytes

        public static void transferBytes​(RandomAccessFileOrArray input,
                                         java.io.OutputStream output)
                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • inputStreamToArray

        public static byte[] inputStreamToArray​(java.io.InputStream stream)
                                         throws java.io.IOException
        Reads the full content of a stream and returns them in a byte array
        Parameters:
        stream - the stream to read
        Returns:
        a byte array containing all of the bytes from the stream
        Throws:
        java.io.IOException - if there is a problem reading from the input stream
      • copyBytes

        public static void copyBytes​(IRandomAccessSource source,
                                     long start,
                                     long length,
                                     java.io.OutputStream output)
                              throws java.io.IOException
        Copy bytes from the RandomAccessSource to OutputStream.
        Parameters:
        source - the RandomAccessSource copy from.
        start - start position of source copy from.
        length - length copy to.
        output - the OutputStream copy to.
        Throws:
        java.io.IOException - on error.
      • readFully

        public static void readFully​(java.io.InputStream input,
                                     byte[] b,
                                     int off,
                                     int len)
                              throws java.io.IOException
        Reads len bytes from an input stream.
        Parameters:
        input - the stream to read
        b - the buffer into which the data is read.
        off - an int specifying the offset into the data.
        len - an int specifying the number of bytes to read.
        Throws:
        java.io.IOException - if an I/O error occurs.