01: package com.sun.portal.fabric.tasks;
02:
03: import com.sun.portal.fabric.util.FileUtil;
04:
05: import java.io.File;
06: import java.io.FileOutputStream;
07: import java.io.IOException;
08: import java.util.Date;
09:
10: /**
11: /**
12: * $Id: UploadInfo.java,v 1.3 2005/04/14 13:46:56 rg149970 Exp $
13: * Copyright 2004 Sun Microsystems, Inc. All
14: * rights reserved. Use of this product is subject
15: * to license terms. Federal Acquisitions:
16: * Commercial Software -- Government Users
17: * Subject to Standard License Terms and
18: * Conditions.
19: *
20: * Sun, Sun Microsystems, the Sun logo, and Sun ONE
21: * are trademarks or registered trademarks of Sun Microsystems,
22: * Inc. in the United States and other countries.
23: */
24: public class UploadInfo {
25: private String mName = null;
26: private long mSize = 0;
27: private File mFile = null;
28: private FileOutputStream mOutputStream = null;
29:
30: //constants
31: public static final String STRING_UNDERSCORE = "_";
32:
33: public UploadInfo(String fileName, long fileSize, String tempFileDir)
34: throws IOException {
35: //filename is expected as file.getName()
36: mName = fileName;
37: mSize = fileSize;
38: mFile = createTempFile(tempFileDir);
39: mOutputStream = new FileOutputStream(mFile, true);
40: }
41:
42: private File createTempFile(String tempDir) {
43: String tempFileName = mName + STRING_UNDERSCORE + mSize
44: + STRING_UNDERSCORE + FileUtil.getRandomDirName();
45: tempDir = tempDir + File.separator + "tmp";
46: mFile = new File(tempDir, tempFileName);
47: mName = tempDir + File.separator + tempFileName;
48:
49: return mFile;
50: }
51:
52: public String getName() {
53: return mName;
54: }
55:
56: public void writeBytes(byte[] bytes) throws IOException {
57: mOutputStream.write(bytes);
58:
59: }
60:
61: public boolean deleteFile() {
62: try {
63: mOutputStream.close();
64: } catch (IOException ioe) {
65: ;
66: }
67: boolean retStatus = mFile.delete();
68: return retStatus;
69: }
70:
71: }
|