Class DecompressingResource

java.lang.Object
org.springframework.core.io.AbstractResource
net.solarnetwork.io.DecompressingResource
All Implemented Interfaces:
org.springframework.core.io.InputStreamSource, org.springframework.core.io.Resource

public class DecompressingResource extends org.springframework.core.io.AbstractResource
A Resource that can decompress another Resource.

This implementation uses the Apache Commons Compression library to return InputStream instances from getInputStream() that perform compression detection and automatic decompression. If a compression type cannot be detected then the raw stream will be returned and the compression type will be set to NO_KNOWN_COMPRESSION_TYPE.

Since:
1.47
Version:
1.1
Author:
matt
  • Field Details

    • NO_KNOWN_COMPRESSION_TYPE

      public static final String NO_KNOWN_COMPRESSION_TYPE
      A special type returned by getCompressionType() if the type is not a know compression format, or appears not to be compressed.
      See Also:
  • Constructor Details

    • DecompressingResource

      public DecompressingResource(org.springframework.core.io.Resource source)
      Constructor.
      Parameters:
      source - the source (compressed) resource
    • DecompressingResource

      public DecompressingResource(org.springframework.core.io.Resource source, String compressionType)
      Constructor.
      Parameters:
      source - the source (compressed) resource
      compressionType - the compression type to use, or null to try to automatically detect the type
    • DecompressingResource

      public DecompressingResource(org.springframework.core.io.Resource source, String compressionType, long contentLength)
      Constructor.
      Parameters:
      source - the source (compressed) resource
      compressionType - the compression type to use, or null to try to automatically detect the type
      contentLength - the known uncompressed content length of the resource, or -1 to automatically determine
      Since:
      1.1
  • Method Details

    • getDescription

      public String getDescription()
    • getInputStream

      public InputStream getInputStream() throws IOException
      Throws:
      IOException
    • getCompressionType

      public String getCompressionType()
      Get the detected compression type.
      Returns:
      the detected compression type
    • getURL

      public URL getURL() throws IOException
      Specified by:
      getURL in interface org.springframework.core.io.Resource
      Overrides:
      getURL in class org.springframework.core.io.AbstractResource
      Throws:
      IOException
    • getFile

      public File getFile() throws IOException
      Specified by:
      getFile in interface org.springframework.core.io.Resource
      Overrides:
      getFile in class org.springframework.core.io.AbstractResource
      Throws:
      IOException
    • getFilename

      public String getFilename()
      Specified by:
      getFilename in interface org.springframework.core.io.Resource
      Overrides:
      getFilename in class org.springframework.core.io.AbstractResource
    • exists

      public boolean exists()
      Specified by:
      exists in interface org.springframework.core.io.Resource
      Overrides:
      exists in class org.springframework.core.io.AbstractResource
    • isReadable

      public boolean isReadable()
      Specified by:
      isReadable in interface org.springframework.core.io.Resource
      Overrides:
      isReadable in class org.springframework.core.io.AbstractResource
    • isOpen

      public boolean isOpen()
      Specified by:
      isOpen in interface org.springframework.core.io.Resource
      Overrides:
      isOpen in class org.springframework.core.io.AbstractResource
    • getURI

      public URI getURI() throws IOException
      Specified by:
      getURI in interface org.springframework.core.io.Resource
      Overrides:
      getURI in class org.springframework.core.io.AbstractResource
      Throws:
      IOException
    • contentLength

      public long contentLength() throws IOException
      Specified by:
      contentLength in interface org.springframework.core.io.Resource
      Overrides:
      contentLength in class org.springframework.core.io.AbstractResource
      Throws:
      IOException
    • lastModified

      public long lastModified() throws IOException
      Specified by:
      lastModified in interface org.springframework.core.io.Resource
      Overrides:
      lastModified in class org.springframework.core.io.AbstractResource
      Throws:
      IOException
    • createRelative

      public org.springframework.core.io.Resource createRelative(String relativePath) throws IOException
      Specified by:
      createRelative in interface org.springframework.core.io.Resource
      Overrides:
      createRelative in class org.springframework.core.io.AbstractResource
      Throws:
      IOException