org.niocchi.core
Class MemoryResource

java.lang.Object
  extended by org.niocchi.core.Resource
      extended by org.niocchi.core.MemoryResource

public class MemoryResource
extends Resource

A resource that saves its content (response body) in memory. The buffer capacity can be set with setCapacity(int). The default capacity is 1MiB. If the content is bigger than the buffer capacity, a ResourceException( "buffer overrun" ) is thrown.


Field Summary
 
Fields inherited from class org.niocchi.core.Resource
UNKNOWN_HTTP_STATUS
 
Constructor Summary
MemoryResource()
          Resource constructor.
 
Method Summary
 byte[] getBody()
          Return the body as an array of bytes.
 byte[] getBytes()
          Legacy method.
static int getCapacity()
          Returns the current capacity.
 void save(java.lang.String path_)
          Save this resource content to a file.
static void setCapacity(int capacity_)
          Sets the capacity (in Bytes) for all resources.
 
Methods inherited from class org.niocchi.core.Resource
getBodyLength, getContentEncoding, getContentMimeSubType, getContentMimeType, getContentType, getHeader, getHeaderNames, getHTTPStatus, getRawDataSize, headersToString, isCompressed, isValid
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MemoryResource

public MemoryResource()
Resource constructor.

Method Detail

setCapacity

public static void setCapacity(int capacity_)
Sets the capacity (in Bytes) for all resources.

Parameters:
capacity_ - the capacity in Bytes.

getCapacity

public static int getCapacity()
Returns the current capacity.

Returns:
the current capacity.

getBody

public byte[] getBody()
Return the body as an array of bytes. If the content was received compressed, it is uncompressed.

Returns:
the body

getBytes

public byte[] getBytes()
Legacy method. Identical as getBody().


save

public void save(java.lang.String path_)
          throws java.io.FileNotFoundException,
                 java.io.IOException
Save this resource content to a file. The directories are created if they don't exist. If the content is gzipped, deflated or zipped, it will be uncompressed before being saved.

Specified by:
save in class Resource
Parameters:
path_ - The path to the file;
Throws:
java.io.FileNotFoundException
java.io.IOException