Class ByteArrayResource

java.lang.Object
com.aquima.interactions.foundation.io.resource.ByteArrayResource
All Implemented Interfaces:
IResource

public class ByteArrayResource extends Object implements IResource
This class represents a resource pointing to an array of bytes. It can be opened multiple times.
Since:
6.0
Author:
F. van der Meer
  • Constructor Summary

    Constructors
    Constructor
    Description
    ByteArrayResource(byte[] bytearray)
    Constructs a resource for the specified byte array.
  • Method Summary

    Modifier and Type
    Method
    Description
    This method returns an input stream for the resource.
    asOutputStream(boolean append)
    This method returns an output stream that may be used to write the contents of the resource.
    This method returns a reader for the resource.
    asWriter(boolean append)
    This method returns a writer that may be used to write the contents of the resource.
    boolean
    This method may be used to create the resource.
    boolean
    This method may be used to create the resource as folder.
    byte[]
    This ByteArrayResource specific method returns the internal used byte array.
    This method returns an object containing information about the resource.
    getRelative(String relativePath)
    This method can be used to retrieve a resource relative to the current resource from the same resource manager.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • ByteArrayResource

      public ByteArrayResource(byte[] bytearray)
      Constructs a resource for the specified byte array. The array is mandatory and is readonly accessed.
      Parameters:
      bytearray - An array of bytes which must at least be non-null.
  • Method Details

    • asInputStream

      public InputStream asInputStream() throws ResourceException
      Description copied from interface: IResource
      This method returns an input stream for the resource. The method will fail with an exception when the resource does not exist. The returned input stream should be closed by the invoking method.
      Specified by:
      asInputStream in interface IResource
      Returns:
      Input stream that can be used to read the contents of the resource.
      Throws:
      ResourceException - This exception is thrown when the resource could not be read.
    • asOutputStream

      public OutputStream asOutputStream(boolean append) throws ResourceException
      Description copied from interface: IResource
      This method returns an output stream that may be used to write the contents of the resource. The append parameter may be used to specify if data written to the output stream should be appended to the resource (true) or if the resource should be overwritten by the data added to the output stream (false).
      Specified by:
      asOutputStream in interface IResource
      Parameters:
      append - Boolean indicating if the data added to the output stream should be appended to the resource.
      Returns:
      Output stream that may be used to write the contents of the resource.
      Throws:
      ResourceException - This exception is thrown when no output stream is available for the resource (for instance due to the resource being read-only).
    • asReader

      public Reader asReader() throws ResourceException
      Description copied from interface: IResource
      This method returns a reader for the resource. The method will fail with an exception when the resource does not exist. The returned reader should be closed by the invoking method.
      Specified by:
      asReader in interface IResource
      Returns:
      Reader that can be used to read the contents of the resource.
      Throws:
      ResourceException - This exception is thrown when the resource could not be read.
    • asWriter

      public Writer asWriter(boolean append) throws ResourceException
      Description copied from interface: IResource
      This method returns a writer that may be used to write the contents of the resource. The append parameter may be used to specify if data written to the writer should be appended to the resource (true) or if the resource should be overwritten by the data added to the writer (false).
      Specified by:
      asWriter in interface IResource
      Parameters:
      append - Boolean indicating if the data added to the writer should be appended to the resource.
      Returns:
      Writer that may be used to write the contents of the resource.
      Throws:
      ResourceException - This exception is thrown when no writer is available for the resource (for instance due to the resource being read-only).
    • createFile

      public boolean createFile() throws ResourceException
      Description copied from interface: IResource
      This method may be used to create the resource. This method is only applicable for resources that have been requested through the getRelative method, and that do not yet exist. The method returns a boolean indicating if the resource was actually created. When this method is invoked on a resource from a read only resource manager, an exception is thrown.
      Specified by:
      createFile in interface IResource
      Returns:
      boolean indicating if the resource was actually created.
      Throws:
      ResourceException - This exception is thrown when the method is invoked on a resource from a read only resource manager.
    • createFolder

      public boolean createFolder() throws ResourceException
      Description copied from interface: IResource
      This method may be used to create the resource as folder. This method is only applicable for resources that have been requested through the getRelative method, and that do not yet exist. The method returns a boolean indicating if the resource folder was actually created. When this method is invoked on a resource from a read only resource manager, an exception is thrown.
      Specified by:
      createFolder in interface IResource
      Returns:
      boolean indicating if the resource folder was actually created.
      Throws:
      ResourceException - This exception is thrown when the method is invoked on a resource from a read only resource manager.
    • getInfo

      public IResourceInfo getInfo()
      Description copied from interface: IResource
      This method returns an object containing information about the resource. The information object may be used to determine if the resource actually exists, if it is read only, etc...
      Specified by:
      getInfo in interface IResource
      Returns:
      Object containing information about the resource.
    • getRelative

      public IResource getRelative(String relativePath) throws ResourceException
      Description copied from interface: IResource
      This method can be used to retrieve a resource relative to the current resource from the same resource manager. The returned resource may not yet exist. This method is only supported for resources of the type 'folder'.
      Specified by:
      getRelative in interface IResource
      Parameters:
      relativePath - relative path to current protocol and location
      Returns:
      A resource object
      Throws:
      ResourceException - when the path-format is incorrect
    • getBytes

      public byte[] getBytes()
      This ByteArrayResource specific method returns the internal used byte array.
      Returns:
      The byte array, containing this resources content, never null.