org.niocchi.core
Class DiskResource

java.lang.Object
  extended by org.niocchi.core.Resource
      extended by org.niocchi.core.DiskResource
Direct Known Subclasses:
GenericResource

public class DiskResource
extends Resource

A resource that saves its content (the response body) into a temporary file. The method save(path) is used to move the content from this tmp file to a specific path. This method handles the uncompressing if needed and delete the tmp file.

If the content can be discarded after being processed, the programmer can access the tmp file directly with getTmpFileAbsolutePath(). Note that the content in the tmp file may be compressed (compression is enabled by default, check Crawler.setAllowCompression(boolean)) and if save() is not called, the tmp file needs to be explicitly deleted.


Field Summary
 
Fields inherited from class org.niocchi.core.Resource
UNKNOWN_HTTP_STATUS
 
Constructor Summary
DiskResource()
          Resource constructor.
 
Method Summary
 java.lang.String getTmpFileAbsolutePath()
          Returns the absolute path of the tmp file that holds the body if some content has been crawled or null otherwise.
 void save(java.lang.String path_)
          If the body is compressed (gzipped, deflated or zipped) it is uncompressed from the tmp file into the target file and the tmp file is deleted.
 
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

DiskResource

public DiskResource()
Resource constructor.

Method Detail

getTmpFileAbsolutePath

public java.lang.String getTmpFileAbsolutePath()
Returns the absolute path of the tmp file that holds the body if some content has been crawled or null otherwise.

Returns:
the absolute path or null.

save

public void save(java.lang.String path_)
          throws java.io.FileNotFoundException,
                 java.io.IOException
If the body is compressed (gzipped, deflated or zipped) it is uncompressed from the tmp file into the target file and the tmp file is deleted. If the body is not compressed, the tmp file is renamed as the target file.

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