public interface File extends HierarchyItem
Defines methods that WebDAV server file items must implement.
In addition to methods provided by HierarchyItem
this interface also provides methods for reading and writing file content.
getContentType()> method must return the MIME type of the file.
| Modifier and Type | Method and Description |
|---|---|
long |
getContentLength()
Gets the size of the file content in bytes.
|
String |
getContentType()
Gets the media type of the file.
|
String |
getEtag()
Gets entity tag - string that identifies current state of resource's content.
|
void |
read(OutputStream output,
long startIndex,
long count)
Writes the content of the file to the specified stream.
|
long |
write(InputStream content,
String contentType,
long startIndex,
long totalFileSize)
Saves the content of the file from the specified stream to the WebDAV repository.
|
copyTo, delete, getCreated, getModified, getName, getPath, getProperties, getPropertyNames, moveTo, updatePropertiesString getContentType() throws ServerException
Mime-type provided by this method is returned in a Content-Type header with GET request.
When deciding which action to perform when downloading a file some WebDAV clients and browsers (such as Internet Explorer) rely on file extension, while others (such as Firefox) rely on Content-Type header returned by server. For identical behavior in all browsers and WebDAV clients your server must return a correct mime-type with a requested file.
ServerException - In case of an error.String getEtag() throws ServerException
ServerException - In case of an errorlong getContentLength()
throws ServerException
ServerException - In case of an error.void read(OutputStream output, long startIndex, long count) throws ServerException, IOException
Client application can request only a part of a file specifying Range header. Download managers may use this header to download single file using several threads at a time.
output - Output stream.startIndex - Zero-bazed byte offset in file content at which to begin copying bytes to the output stream.count - Number of bytes to be written to the output stream.ServerException - In case of an error.IOException - I/O exception occurred.
<<<< readFileImpl >>>>long write(InputStream content, String contentType, long startIndex, long totalFileSize) throws LockedException, ServerException, IOException
If totalContentLength is -1 then content parameter
contains entire file content. startIndex parameter
is always 0 in this case.
The Java WebDAV Server Engine can process two types of upload requests:
To provide information about what segment of a file is being uploaded PUT request will contain optional Content-Range: bytes XXX-XXX/XXX header.
The following example demonstrates upload to WebDAV server using POST with multipart encoding by legacy web browser. The file will be created in /mydocs/ folder.
<html>
<head><title>POST Upload to WebDAV Server</title></head>
<body>
<form action="/mydocs/" method="post" enctype="multipart/form-data">
<input type="file" name="dummyname" /><br />
<input type="submit" />
</form>
</body>
</html>
content - InputStream to read the content of the file from.contentType - Indicates media type of the file.startIndex - Index in file to which corresponds first byte in content.totalFileSize - Total size of the file being uploaded. -1 if size is unknown.LockedException - File was locked and client did not provide lock token.ServerException - In case of an error.IOException - I/O error.Copyright © ITHit. All Rights Reserved.