Class FastByteArrayInputStream

java.lang.Object
java.io.InputStream
com.cedarsoftware.util.FastByteArrayInputStream
All Implemented Interfaces:
Closeable, AutoCloseable

public class FastByteArrayInputStream extends InputStream
Faster version of ByteArrayInputStream that does not have synchronized methods.
Author:
John DeRegnaucourt ([email protected])
Copyright (c) Cedar Software LLC

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

License

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
  • Constructor Details

    • FastByteArrayInputStream

      public FastByteArrayInputStream(byte[] buf)
  • Method Details

    • read

      public int read()
      Specified by:
      read in class InputStream
    • read

      public int read(byte[] b, int off, int len)
      Overrides:
      read in class InputStream
    • skip

      public long skip(long n)
      Overrides:
      skip in class InputStream
    • available

      public int available()
      Overrides:
      available in class InputStream
    • mark

      public void mark(int readLimit)
      Overrides:
      mark in class InputStream
    • reset

      public void reset()
      Overrides:
      reset in class InputStream
    • markSupported

      public boolean markSupported()
      Overrides:
      markSupported in class InputStream
    • readAllBytes

      public byte[] readAllBytes()
      Reads all remaining bytes from this input stream. This method provides an optimized implementation that directly copies from the internal buffer rather than using the default InputStream implementation which uses intermediate buffers.

      This method is compatible with JDK 9+ where it overrides InputStream.readAllBytes(), and works as a regular method on JDK 8.

      Overrides:
      readAllBytes in class InputStream
      Returns:
      a byte array containing all remaining bytes from this stream
    • readNBytes

      public byte[] readNBytes(int len)
      Reads up to a specified number of bytes from this input stream. This method provides an optimized implementation that directly copies from the internal buffer.

      This method is compatible with JDK 11+ where it overrides InputStream.readNBytes(int), and works as a regular method on earlier JDK versions.

      Overrides:
      readNBytes in class InputStream
      Parameters:
      len - the maximum number of bytes to read
      Returns:
      a byte array containing the bytes read from this stream
      Throws:
      IllegalArgumentException - if len is negative
    • transferTo

      public long transferTo(OutputStream out) throws IOException
      Transfers all remaining bytes from this input stream to the given output stream. This method provides an optimized implementation that writes directly from the internal buffer in a single operation.

      This method is compatible with JDK 9+ where it overrides InputStream.transferTo(OutputStream), and works as a regular method on JDK 8.

      Overrides:
      transferTo in class InputStream
      Parameters:
      out - the output stream to write to
      Returns:
      the number of bytes transferred
      Throws:
      IOException - if an I/O error occurs when writing to the output stream
      NullPointerException - if out is null
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream