public class FileCacher
extends java.lang.Object
User: Mike Date: 11/11/11 Time: 9:02 AM
Constructor and Description |
---|
FileCacher(ScrapingSession session,
java.lang.String cacheDirectory)
Creates the scrape cache with the given utility, and sets the default log saving behavior.
|
Modifier and Type | Method and Description |
---|---|
java.io.File |
cacheBytes(java.lang.String name,
byte[] bytes)
Caches a byte array as a file using a given path for the output in the zip
|
java.io.File |
cacheFile(java.lang.String name,
java.io.File file)
Caches a file using a given path for the output in the zip
|
java.io.File |
cacheText(java.lang.String name,
java.lang.String content)
Caches a string with a given name
|
java.io.File |
cacheText(java.lang.String name,
java.lang.String content,
java.lang.String encoding)
Caches a string with a given name
|
java.io.File |
endCache()
Ends the cache, either zipping or renaming the containing directory.
|
java.io.File |
getCacheDirectory()
Returns the cache directory being used to store files
|
java.lang.String |
getDescription()
Returns the descriptive text to use in the cache file name
|
boolean |
getShouldSaveCountInFileName()
Returns whether or not the number of the cached page will be saved in the name of the file
|
boolean |
getShouldSaveLogs()
Gets the current log saving policy.
|
boolean |
getZipOnEnd()
Returns whether or not the cache should be compressed when everything is written to it
|
void |
setDescription(java.lang.String description)
Sets the descriptive text to use in the cache file name
|
void |
setShouldSaveCountInFileName(boolean shouldSaveCountInFileName)
Sets whether or not to include the current cached page number in the file name.
|
void |
setShouldSaveLogs(boolean shouldSaveLogs)
Sets the log saving behavior.
|
void |
setZipOnEnd(boolean zipOnEnd)
Sets whether or not the cache should be compressed when everything is written to it
|
java.lang.String |
toString() |
public FileCacher(@Nullable ScrapingSession session, @Nullable java.lang.String cacheDirectory)
session
- The session associated with the cachecacheDirectory
- The directory where cached files will be savedpublic void setShouldSaveLogs(boolean shouldSaveLogs)
shouldSaveLogs
- True if logs should be included in the cache, false otherwisepublic boolean getShouldSaveLogs()
public void setZipOnEnd(boolean zipOnEnd)
zipOnEnd
- True if zipping should occur, false to leave it in a directory structurepublic boolean getZipOnEnd()
public void setDescription(java.lang.String description)
description
- The text to use in the cache file namepublic java.lang.String getDescription()
public void setShouldSaveCountInFileName(boolean shouldSaveCountInFileName)
shouldSaveCountInFileName
- True if the file number should be saved at the beginning of the file namepublic boolean getShouldSaveCountInFileName()
@Nullable public java.io.File cacheText(java.lang.String name, java.lang.String content)
name
- The name for the file (alterations such as timestamps will occur)content
- The content for the cached filejava.lang.IllegalArgumentException
- Name or extension is null@Nullable public java.io.File cacheText(@Nullable java.lang.String name, @Nullable java.lang.String content, @Nullable java.lang.String encoding)
name
- The name for the file (alterations such as timestamps will occur)content
- The content for the cached fileencoding
- The character encoding to use when writing this file to the cachejava.lang.IllegalArgumentException
- Name or extension is null@Nullable public java.io.File cacheFile(@Nullable java.lang.String name, @Nullable java.io.File file)
name
- The name to use for the file in the cache, including the extensionfile
- The file to cache@Nullable public java.io.File cacheBytes(@Nullable java.lang.String name, @Nullable byte[] bytes)
name
- The name to use for the file in the cache, including the extensionbytes
- The bytes to cache@Nullable public java.io.File endCache() throws java.io.IOException
java.io.IOException
- Error writing the zip file or renaming the directorypublic final java.io.File getCacheDirectory()
@NotNull public java.lang.String toString()
toString
in class java.lang.Object