KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > appserv > management > base > UploadDownloadMgr


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.appserv.management.base;
25
26 import java.io.IOException JavaDoc;
27 import java.io.File JavaDoc;
28
29 import com.sun.appserv.management.base.XTypes;
30 import com.sun.appserv.management.base.AMX;
31 import com.sun.appserv.management.base.Utility;
32 import com.sun.appserv.management.base.Singleton;
33
34 /**
35     Manages uploading or downloading of files to/from the server. Generally
36     for internal use only.
37  */

38 public interface UploadDownloadMgr
39     extends AMX, Utility, Singleton
40 {
41 /** The j2eeType as returned by {@link com.sun.appserv.management.base.AMX#getJ2EEType}. */
42     public static final String JavaDoc J2EE_TYPE = XTypes.UPLOAD_DOWNLOAD_MGR;
43
44     /**
45         Initiate an upload operation. The supplied name is intended as
46         a prefix; if it contains file system separators such as ":", "/" or "\",
47         they are converted into the "_" character.
48      
49      @param name name to use for the temp file, may be null
50      @param totalSize total size of the file to upload
51      @return an opaque identifier describing this file upload
52      */

53     public Object JavaDoc initiateUpload(String JavaDoc name, long totalSize )
54             throws IOException JavaDoc;
55
56     /**
57         Upload bytes for the specified upload
58         
59      @param uploadID the id obtained from initiateUpload()
60      @param bytes more bytes to be uploaded
61      @return true if the total upload has been completed, false otherwise
62      @throws an Exception if a problem occurred
63      */

64     public boolean uploadBytes(Object JavaDoc uploadID, byte[] bytes)
65         throws IOException JavaDoc;
66         
67
68     /**
69         Ownership of transferred bytes (now in a File) are transferred to
70         the caller.
71         
72         @param uploadID the id obtained from initiateUpload()
73         @return a File object for a file containing the uploaded bytes
74         @throws an Exception if the uploadID doesn't exist, or has not finished.
75      */

76     public File JavaDoc takeUpload( Object JavaDoc uploadID );
77
78
79
80     /**
81      Initiates a file download with the given filename. This operation
82      may be used locally or remotely, but the File specified must exist
83      and be readable on the server.
84      
85      @param theFile an accessible File
86      @param deleteWhenDone whether to delete the file when done
87      @return the downloadID to be used for subequent calls to downloadBytes()
88      */

89     public Object JavaDoc initiateDownload( File JavaDoc theFile, boolean deleteWhenDone )
90         throws IOException JavaDoc;
91         
92     /**
93         Get the total length the download will be, in bytes.
94         
95         @param downloadID the dowloadID, as obtained from initiateDownload()
96      */

97     public long getDownloadLength( final Object JavaDoc downloadID );
98
99     /**
100         @return the maximum allowable request size for downloading bytes
101      */

102     public int getMaxDownloadChunkSize();
103
104     /**
105      Download bytes from the server using the downloadID obtained from
106      initiateDownload().
107      <p>
108      The bufferSize is the requested number of bytes to
109      be received. If the size of the returned byte[] is less than
110      the requestSize, then the transfer has completed, and the
111      downloadID is no longer valid. An attempt to read more than
112      the allowed maximum size will throw an exception. The caller
113      can check the total download size in advance via
114      getDownloadLength().
115      
116      @param downloadID the id from initiateDownload()
117      @return bytes remaining bytes, up to the request size
118      */

119     public byte[] downloadBytes( Object JavaDoc downloadID, int requestSize )
120         throws IOException JavaDoc;
121
122
123
124 }
125
Popular Tags