org.archive.wayback.core
Class Resource

java.lang.Object
  extended by java.io.InputStream
      extended by org.archive.wayback.core.Resource
All Implemented Interfaces:
Closeable
Direct Known Subclasses:
ArcResource, WarcResource

public abstract class Resource
extends InputStream

Abstraction on top of a document stored in a WaybackCollection. Currently implemented subclasses include ArcResource and WarcResource. This implementation needs some pretty drastic refactoring.. May have to wait for 2.0. This should be a byte-oriented record, and allow wrapping the interior byte-stream in on the more full featured HTTP libraries (jetty/apache-http-client/w3c-http-reference). For now, it is a system-wide assumption that all resources are HTTP based.

Version:
$Date: 2010-09-29 05:28:38 +0700 (Wed, 29 Sep 2010) $, $Revision: 3262 $
Author:
Brad Tofel

Constructor Summary
Resource()
           
 
Method Summary
 int available()
           
abstract  void close()
           
abstract  Map<String,String> getHttpHeaders()
          Assumes an HTTP response - return the HTTP headers, not including the HTTP Message header
abstract  long getRecordLength()
           
abstract  int getStatusCode()
          Assumes an HTTP resource - return the HTTP response code
 void mark(int readlimit)
           
 boolean markSupported()
           
 int read()
           
 int read(byte[] b)
           
 int read(byte[] b, int off, int len)
           
 void reset()
           
 void setChunkedEncoding()
          indicate that there is a Transfer-Encoding: chunked header, so the input data should be dechunked as it is read.
protected  void setInputStream(InputStream is)
           
 long skip(long n)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Resource

public Resource()
Method Detail

close

public abstract void close()
                    throws IOException
Specified by:
close in interface Closeable
Overrides:
close in class InputStream
Throws:
IOException

getStatusCode

public abstract int getStatusCode()
Assumes an HTTP resource - return the HTTP response code

Returns:
the HTTP response code from the HTTP message

getRecordLength

public abstract long getRecordLength()
Returns:
the size in bytes of the record payload, including HTTP header

getHttpHeaders

public abstract Map<String,String> getHttpHeaders()
Assumes an HTTP response - return the HTTP headers, not including the HTTP Message header

Returns:
key-value Map of HTTP headers

setInputStream

protected void setInputStream(InputStream is)

setChunkedEncoding

public void setChunkedEncoding()
                        throws IOException
indicate that there is a Transfer-Encoding: chunked header, so the input data should be dechunked as it is read. This method actually peeks ahead to verify that there is a hex-encoded chunk length before assuming the data is chunked.

Throws:
IOException - for usual reasons

available

public int available()
              throws IOException
Overrides:
available in class InputStream
Throws:
IOException

mark

public void mark(int readlimit)
Overrides:
mark in class InputStream

markSupported

public boolean markSupported()
Overrides:
markSupported in class InputStream

read

public int read()
         throws IOException
Specified by:
read in class InputStream
Throws:
IOException

read

public int read(byte[] b,
                int off,
                int len)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

read

public int read(byte[] b)
         throws IOException
Overrides:
read in class InputStream
Throws:
IOException

reset

public void reset()
           throws IOException
Overrides:
reset in class InputStream
Throws:
IOException

skip

public long skip(long n)
          throws IOException
Overrides:
skip in class InputStream
Throws:
IOException


Copyright © 2005-2011 Internet Archive. All Rights Reserved.