com.ithit.webdav.server
Interface File

All Superinterfaces:
HierarchyItem

public interface File
extends HierarchyItem

Represents a file in the WebDAV repository.

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.


Method Summary
 long getContentLength()
          Gets the size of the file content in bytes.
 java.lang.String getContentType()
          Gets the media type of the file.
 void read(java.io.OutputStream output, long startIndex, long count)
          Writes the content of the file to the specified stream.
 void write(java.io.InputStream content, java.lang.String contentType, long startIndex, long totalFileSize)
          Saves the content of the file from the specified stream to the WebDAV repository.
 
Methods inherited from interface com.ithit.webdav.server.HierarchyItem
copyTo, delete, getCreated, getModified, getName, getPath, getProperties, getPropertyNames, moveTo, updateProperties
 

Method Detail

getContentType

java.lang.String getContentType()
                                throws ServerException
Gets the media type of the file.

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.

Returns:
MIME type of the file.
Throws:
ServerException - In case of an error.

getContentLength

long getContentLength()
                      throws ServerException
Gets the size of the file content in bytes.

Returns:
Length of the file content in bytes.
Throws:
ServerException - In case of an error.

read

void read(java.io.OutputStream output,
          long startIndex,
          long count)
          throws ServerException,
                 java.io.IOException
Writes the content of the file to the specified stream.

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.

Parameters:
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.
Throws:
ServerException - In case of an error.
java.io.IOException - I/O exception occurred.

write

void write(java.io.InputStream content,
           java.lang.String contentType,
           long startIndex,
           long totalFileSize)
           throws LockedException,
                  ServerException,
                  java.io.IOException
Saves the content of the file from the specified stream to the WebDAV repository.

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 rich client application will attach optional Content-Range: bytes XXX-XXX/XXX header to PUT request.

The following example demonstrates upload to WebDAV server using POST with multipart encoding. 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>
 

Parameters:
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.
Throws:
LockedException - File was locked and client did not provide lock token.
ServerException - In case of an error.
java.io.IOException - I/O error.


Copyright © 2009 ITHit. All Rights Reserved.