|
|||||||||
| Home >> All >> raining >> [ server overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
raining.server
Class FileInfo

java.lang.Objectraining.server.FileInfo
- public class FileInfo
- extends java.lang.Object
Maintains cacheable information of a file such as content, when last
updated in cache, and methods to update the cache, and tell the cache
if it needs updating.
TODO: should store as ByteBuffers
also i can keep header and content separate, and use a gathered
write. First i need to change that in NioSocket.
TODO: server_root needs to be set, i think.
RK modified on 20031116 14:44:39: header is now part of content.
Taken from Bulka's code (Java Performance and Scalability)
and modified.
This needs to be redone. The server sample wasn't written in an OO
manner.
I need to look into caching the header. Currently headers are managed by
HTTPResponse implementations.
We need to have a CachedObject interface with a needsRefreshing and
update() contract.
| Field Summary | |
protected java.nio.ByteBuffer |
content
file content along with header. |
private byte[] |
headers
HTTP header. |
protected long |
lastModified
when was the file updated - required for if-modified-since - this is a cached time. |
protected long |
lastUpdate
when was the content last updated. |
private byte[] |
logSecondHalf
unused currently |
private static java.lang.String |
P
|
static java.lang.String |
server_root
|
protected java.io.File |
targ
file object, stored here since its required to check whether the file has been modified or not since it was last read up. |
protected java.lang.String |
url
the url or filename associated with this object. |
| Constructor Summary | |
FileInfo(byte[] h,
byte[] c,
java.lang.String u)
constructor taking header and content and url. |
|
FileInfo(byte[] h,
long lu,
java.lang.String u)
constructor taking a header but no content. |
|
FileInfo(java.lang.String u)
constructor that takes only filename. |
|
| Method Summary | |
static byte[] |
getBytes(java.lang.String url)
read up the files contents into a byte array. |
java.nio.ByteBuffer |
getContent()
returns content as a ByteByffer, after duplicating the buffer. |
static FileInfo |
getFileInfo(java.lang.String url)
static method to get a file info object. |
byte[] |
getHeaders()
|
long |
getLastUpdate()
|
byte[] |
getLogSecondHalf()
|
boolean |
ifModifiedSince(long requestedTime)
returns true if the file has been modified since the time requested by the user (in if-Modified-Since field of header). |
static byte[] |
join(byte[] a,
byte[] b)
joins 2 byte arrays and returns a new array. |
static void |
main(java.lang.String[] args)
|
boolean |
needsRefreshing()
returns true if the files actual lastModified is greater than the cache update time. |
void |
setContent(byte[] c)
|
void |
setContent(java.nio.ByteBuffer c)
|
void |
setHeaders(byte[] h)
|
void |
setLastUpdate(long t)
|
void |
setLogSecondHalf(byte[] s)
|
void |
update()
updates the cache whenever the file is updated. |
static java.io.File |
urlToFile(java.lang.String url)
|
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
headers
private byte[] headers
- HTTP header.
ignored for the present. header is now part of content.
content
protected java.nio.ByteBuffer content
- file content along with header.
lastUpdate
protected long lastUpdate
- when was the content last updated.
lastModified
protected long lastModified
- when was the file updated - required for if-modified-since -
this is a cached time.
logSecondHalf
private byte[] logSecondHalf
- unused currently
url
protected java.lang.String url
- the url or filename associated with this object. No longer
required to be stored since the File object is being stored. But
maybe can be kept for some time.
targ
protected java.io.File targ
- file object, stored here since its required to check whether the
file has been modified or not since it was last read up.
server_root
public static java.lang.String server_root
P
private static final java.lang.String P
- See Also:
- Constant Field Values
| Constructor Detail |
FileInfo
public FileInfo(byte[] h,
long lu,
java.lang.String u)
- constructor taking a header but no content.
why would you use this ?
FileInfo
public FileInfo(byte[] h,
byte[] c,
java.lang.String u)
- constructor taking header and content and url.
Header and content are concatenated and stored as content.
This approach exists if you
wish to keep sending fresh headers with current/lazy date.
however, i wish to keep static headers. need to ascertain whether
this breaks the rfc.
FileInfo
public FileInfo(java.lang.String u)
- constructor that takes only filename.
This allows us to create
the OK header since that needs file date also.
| Method Detail |
getFileInfo
public static FileInfo getFileInfo(java.lang.String url) throws java.io.IOException
- static method to get a file info object.
update
public void update()
throws java.io.IOException
- updates the cache whenever the file is updated.
this also recreates the header RK modified on 20031116 14:44:11
getBytes
public static byte[] getBytes(java.lang.String url) throws java.io.IOException
- read up the files contents into a byte array.
why am i adding the CRLF at start. doesnt the header have that at
end already. RK 20031116 15:12:54
setHeaders
public void setHeaders(byte[] h)
setContent
public void setContent(byte[] c)
setContent
public void setContent(java.nio.ByteBuffer c)
setLastUpdate
public void setLastUpdate(long t)
setLogSecondHalf
public void setLogSecondHalf(byte[] s)
getHeaders
public byte[] getHeaders()
getContent
public java.nio.ByteBuffer getContent()
- returns content as a ByteByffer, after duplicating the buffer.
Thus, multiple threads may use the same at a time.
getLastUpdate
public long getLastUpdate()
getLogSecondHalf
public byte[] getLogSecondHalf()
urlToFile
public static java.io.File urlToFile(java.lang.String url)
needsRefreshing
public boolean needsRefreshing()
- returns true if the files actual lastModified is greater than
the cache update time.
This invokes an expensive system call to find out file update
time.
join
public static byte[] join(byte[] a,
byte[] b)
- joins 2 byte arrays and returns a new array.
written for the ctor that takes header and content as separate
arrays.
ifModifiedSince
public boolean ifModifiedSince(long requestedTime)
- returns true if the file has been modified since the
time requested by the user (in if-Modified-Since field of
header).
main
public static void main(java.lang.String[] args)
|
|||||||||
| Home >> All >> raining >> [ server overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
raining.server.FileInfo