Class HttpFileImpl
- java.lang.Object
-
- net.officefloor.web.resource.impl.AbstractHttpResource
-
- net.officefloor.web.resource.impl.HttpFileImpl
-
- All Implemented Interfaces:
java.io.Closeable,java.lang.AutoCloseable,FileCompleteCallback,HttpFile,HttpResource
public class HttpFileImpl extends AbstractHttpResource implements HttpFile, FileCompleteCallback
AbstractHttpFileimplementation.- Author:
- Daniel Sagenschneider
-
-
Field Summary
-
Fields inherited from class net.officefloor.web.resource.impl.AbstractHttpResource
path
-
-
Constructor Summary
Constructors Constructor Description HttpFileImpl(java.lang.String path, java.nio.file.Path cleanupResourcePath, java.nio.channels.FileChannel file, HttpHeaderValue contentEncoding, HttpHeaderValue contentType, java.nio.charset.Charset charset)Initiate an existingHttpFile.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voidcomplete(java.nio.channels.FileChannel file, boolean isWritten)Invoked on completion of writing theFileChannelcontent.java.nio.charset.CharsetgetCharset()Obtains theCharsetfor the contents.HttpHeaderValuegetContentEncoding()Obtains theContent-Encodingfor thisHttpFile.HttpHeaderValuegetContentType()Obtains theContent-Typefor thisHttpFile.booleanisExist()Indicates if thisHttpResourceexists.voidwriteTo(HttpResponse response)Writes theHttpFileto theHttpResponse.-
Methods inherited from class net.officefloor.web.resource.impl.AbstractHttpResource
equals, getPath, hashCode
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface net.officefloor.web.resource.HttpResource
getPath
-
-
-
-
Constructor Detail
-
HttpFileImpl
public HttpFileImpl(java.lang.String path, java.nio.file.Path cleanupResourcePath, java.nio.channels.FileChannel file, HttpHeaderValue contentEncoding, HttpHeaderValue contentType, java.nio.charset.Charset charset)Initiate an existingHttpFile.- Parameters:
path- Path.cleanupResourcePath- ResourcePathto clean up. May benull.file-FileChannelto the file.contentEncoding-Content-Encoding.contentType-Content-Type.charset-Charset.
-
-
Method Detail
-
isExist
public boolean isExist()
Description copied from interface:HttpResourceIndicates if this
HttpResourceexists. Should thisHttpResourcenot exist, only the path will be available.This allows for caching of
HttpResourceinstances not existing.- Specified by:
isExistin interfaceHttpResource- Returns:
trueif thisHttpResourceexists.
-
getContentEncoding
public HttpHeaderValue getContentEncoding()
Description copied from interface:HttpFileObtains theContent-Encodingfor thisHttpFile.- Specified by:
getContentEncodingin interfaceHttpFile- Returns:
Content-Encodingfor thisHttpFile.- See Also:
ResourceTransformer
-
getContentType
public HttpHeaderValue getContentType()
Description copied from interface:HttpFileObtains theContent-Typefor thisHttpFile.- Specified by:
getContentTypein interfaceHttpFile- Returns:
Content-Typefor thisHttpFile.- See Also:
FileTypeDetector
-
getCharset
public java.nio.charset.Charset getCharset()
Description copied from interface:HttpFileObtains theCharsetfor the contents.- Specified by:
getCharsetin interfaceHttpFile- Returns:
Charsetornullif contents are not text or theCharsetis unknown.- See Also:
ResourceSystem,ResourceSystemContext
-
writeTo
public void writeTo(HttpResponse response) throws java.io.IOException
Writes theHttpFileto theHttpResponse.- Specified by:
writeToin interfaceHttpFile- Parameters:
response-HttpResponse- Throws:
java.io.IOException- If fails to write theHttpFile.
-
complete
public void complete(java.nio.channels.FileChannel file, boolean isWritten) throws java.io.IOExceptionDescription copied from interface:FileCompleteCallbackInvoked on completion of writing the
FileChannelcontent.Note that may also be invoked if content was not written (rather cancelled).
Typical use is to close the
FileChannelonce complete.WARNING: this is typically invoked on the
SocketChannelThreadso should not invoke any long running operations.- Specified by:
completein interfaceFileCompleteCallback- Parameters:
file-FileChannelfrom the write.isWritten-trueindicates whether written, whilefalseindicates cancelled.- Throws:
java.io.IOException- If issue in interacting withFileChannel.
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Throws:
java.io.IOException
-
-