Class IOResources

java.lang.Object
org.eclipse.jetty.io.IOResources

public class IOResources extends Object
Common IO operations for Resource content.
  • Constructor Details

    • IOResources

      public IOResources()
  • Method Details

    • toRetainableByteBuffer

      public static RetainableByteBuffer toRetainableByteBuffer(org.eclipse.jetty.util.resource.Resource resource, ByteBufferPool.Sized bufferPool) throws IllegalArgumentException

      Reads the contents of a Resource into a RetainableByteBuffer.

      The resource must not be a directory, must exists and there must be a way to access its contents.

      Multiple optimized methods are used to access the resource's contents but if they all fail, Resource.newInputStream() is used as a fallback.

      Parameters:
      resource - the resource to be read.
      bufferPool - the ByteBufferPool.Sized to get buffers from. null means allocate new buffers as needed.
      Returns:
      a RetainableByteBuffer containing the resource's contents.
      Throws:
      IllegalArgumentException - if the resource is a directory or does not exist or there is no way to access its contents.
    • asContentSource

      public static Content.Source asContentSource(org.eclipse.jetty.util.resource.Resource resource, ByteBufferPool.Sized bufferPool, long offset, long length) throws IllegalArgumentException

      Gets a Content.Source with a range of the contents of a resource.

      The resource must not be a directory, must exists and there must be a way to access its contents.

      Multiple optimized methods are used to access the resource's contents but if they all fail, Resource.newInputStream() is used as a fallback.

      Parameters:
      resource - the resource from which to get a Content.Source.
      bufferPool - the ByteBufferPool.Sized to get buffers from. null means allocate new buffers as needed.
      offset - the offset byte of the resource to start from. Must be greater than or equal to 0 and less than the resource length (if known).
      length - the length of the content to make available, -1 for the full length, otherwise must be greater than 0 and less than or equal to the resource length (if known) minus the offset.
      Returns:
      a Content.Source.
      Throws:
      IndexOutOfBoundsException - if the offset or length are out of range.
      IllegalArgumentException - if the resource is a directory or does not exist or there is no way to access its contents.
      See Also:
    • asInputStream

      public static InputStream asInputStream(org.eclipse.jetty.util.resource.Resource resource) throws IllegalArgumentException

      Gets an InputStream with the contents of a resource.

      The resource must not be a directory, must exist and must return non-null to Resource.newInputStream().

      Parameters:
      resource - the resource from which to get an InputStream.
      Returns:
      the InputStream.
      Throws:
      IllegalArgumentException - if the resource is a directory or does not exist or Resource.newInputStream() returns null.
    • copy

      public static void copy(org.eclipse.jetty.util.resource.Resource resource, Content.Sink sink, ByteBufferPool.Sized bufferPool, long offset, long length, org.eclipse.jetty.util.Callback callback) throws IllegalArgumentException

      Performs an asynchronous copy of a subset of the contents of a resource to a sink, using the given buffer pool and buffer characteristics.

      The resource must not be a directory, must exist and there must be a way to access its contents.

      Multiple optimized methods are used to access the resource's contents but if they all fail, Content.Source.from(ByteBufferPool.Sized, InputStream, long, long) is used as a fallback to perform the copy.

      Parameters:
      resource - the resource to copy from.
      sink - the sink to copy to.
      bufferPool - the ByteBufferPool to get buffers from. null means allocate new buffers as needed.
      offset - the offset byte of the resource to start from.
      length - the length of the resource's contents to copy, -1 for the full length.
      callback - the callback to notify when the copy is done.
      Throws:
      IllegalArgumentException