public class StatusConsumer extends Object
StreamJSONStatusList.ReadableWritableJSON and
output image files. Currently this StatusConsumer only understands
Twitter JSON, perhaps making it abstract and turning consume(Status)
into an abstract function that can deal with other types of status would be
sensible| Modifier and Type | Class and Description |
|---|---|
static class |
StatusConsumer.StatusConsumerRedirectStrategy
An extention of the
HttpUtils.MetaRefreshRedirectStrategy which disallows
all redirects and instead remembers a redirect for use later on. |
| Modifier and Type | Field and Description |
|---|---|
static org.apache.log4j.Logger |
logger
The logger
|
static List<SiteSpecificConsumer> |
siteSpecific
the site specific consumers
|
| Constructor and Description |
|---|
StatusConsumer()
for convenience
|
StatusConsumer(boolean outputStats,
File globalStats,
File outputLocation,
List<OutputListener> outputModes) |
| Modifier and Type | Method and Description |
|---|---|
void |
add(String newURL)
Add a URL to process without allowing already seen URLs to be added
|
StatusConsumption |
consume(twitter4j.Status status) |
StatusConsumption |
processAll(twitter4j.Status status)
Process all added URLs
|
File |
resolveURL(URL url,
StatusConsumption cons)
Given a URL, use
urlToImage(URL) to turn the url into a list of
images and write the images into the output location using the names
"image_N.png" |
static String |
sanitizeFilename(String name)
Replaces illegal characters in a filename with "_" illegal characters : :
\ / * ? | < >
|
List<IndependentPair<URL,MBFImage>> |
urlToImage(URL url)
First, try all the
SiteSpecificConsumer instances loaded into
siteSpecific. |
static File |
urlToOutput(URL url,
File outputLocation)
Construct a file in the output location for a given url
|
public static org.apache.log4j.Logger logger
public static final List<SiteSpecificConsumer> siteSpecific
public StatusConsumer(boolean outputStats, File globalStats, File outputLocation, List<OutputListener> outputModes)
outputStats - whether statistics should be outputtedglobalStats - the global statistics fileoutputLocation - the output location for this statusoutputModes - the output modes informed on image downloadspublic StatusConsumer()
public StatusConsumption consume(twitter4j.Status status) throws Exception
status - Exceptionpublic StatusConsumption processAll(twitter4j.Status status) throws IOException
status - StatusConsumption statisticsIOExceptionpublic void add(String newURL)
newURL - public File resolveURL(URL url, StatusConsumption cons)
urlToImage(URL) to turn the url into a list of
images and write the images into the output location using the names
"image_N.png"url - cons - the consumption statspublic List<IndependentPair<URL,MBFImage>> urlToImage(URL url)
SiteSpecificConsumer instances loaded into
siteSpecific. If any consumer takes control of a link the
consumer's output is used
if this fails use
HttpUtils.readURLAsByteArrayInputStream(URL, org.apache.http.client.RedirectStrategy)
with a StatusConsumer.StatusConsumerRedirectStrategy which specifically
disallows redirects to be dealt with automatically and forces this
function to be called for each redirect.url - public static File urlToOutput(URL url, File outputLocation) throws IOException
url - outputLocation - IOExceptionpublic static String sanitizeFilename(String name)
name -