Class HttpFileImpl
java.lang.Object
net.officefloor.web.resource.impl.AbstractHttpResource
net.officefloor.web.resource.impl.HttpFileImpl
- All Implemented Interfaces:
Closeable,AutoCloseable,FileCompleteCallback,HttpFile,HttpResource
Abstract
HttpFile implementation.- Author:
- Daniel Sagenschneider
-
Field Summary
Fields inherited from class net.officefloor.web.resource.impl.AbstractHttpResource
path -
Constructor Summary
ConstructorsConstructorDescriptionHttpFileImpl(String path, Path cleanupResourcePath, FileChannel file, HttpHeaderValue contentEncoding, HttpHeaderValue contentType, Charset charset) Initiate an existingHttpFile. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()voidcomplete(FileChannel file, boolean isWritten) Invoked on completion of writing theFileChannelcontent.Obtains theCharsetfor the contents.Obtains theContent-Encodingfor thisHttpFile.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, hashCodeMethods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface net.officefloor.web.resource.HttpResource
getPath
-
Constructor Details
-
HttpFileImpl
public HttpFileImpl(String path, Path cleanupResourcePath, FileChannel file, HttpHeaderValue contentEncoding, HttpHeaderValue contentType, 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 Details
-
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
Description copied from interface:HttpFileObtains theContent-Encodingfor thisHttpFile.- Specified by:
getContentEncodingin interfaceHttpFile- Returns:
Content-Encodingfor thisHttpFile.- See Also:
-
getContentType
Description copied from interface:HttpFileObtains theContent-Typefor thisHttpFile.- Specified by:
getContentTypein interfaceHttpFile- Returns:
Content-Typefor thisHttpFile.- See Also:
-
getCharset
Description copied from interface:HttpFileObtains theCharsetfor the contents.- Specified by:
getCharsetin interfaceHttpFile- Returns:
Charsetornullif contents are not text or theCharsetis unknown.- See Also:
-
writeTo
Writes theHttpFileto theHttpResponse.- Specified by:
writeToin interfaceHttpFile- Parameters:
response-HttpResponse- Throws:
IOException- If fails to write theHttpFile.
-
complete
Description 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:
IOException- If issue in interacting withFileChannel.
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-