KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > daffodilwoods > daffodildb > server > serversystem > ClobOutPutStream


1 package com.daffodilwoods.daffodildb.server.serversystem;
2
3 import java.io.*;
4
5 import com.daffodilwoods.database.resource.*;
6
7 public class ClobOutPutStream {
8
9   public int lastIndex;
10   private String JavaDoc path;
11
12   public ClobOutPutStream(String JavaDoc clobFileHome0) {
13     path = clobFileHome0+"clob.lob";
14   }
15
16   public int write(InputStream input) throws DException {
17     int len = 0;
18     int length = 0;
19     byte[] buf = new byte[1024];
20     try {
21       FileOutputStream output = new FileOutputStream(path, true);
22       while((len = input.read(buf)) > 0 ){
23           output.write(buf, 0, len);
24           lastIndex += len;
25           length += len;
26       }
27       output.close();
28       return length;
29     }
30     catch (FileNotFoundException ex) {
31       throw new DException("DSE5553", null);
32     }
33     catch (IOException ex) {
34       throw new DException("DSE5556", null);
35     }
36   }
37
38   public long getLength() {
39     File file = new File(path);
40     try {
41       if (file.exists()) {
42         FileInputStream fis = new FileInputStream(path);
43         lastIndex = fis.available();
44         fis.close() ;
45         return lastIndex;
46       }
47          return 0;
48     }
49     catch (IOException ex) {
50       return 0;
51     }
52   }
53 }
54
Popular Tags