KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.serversystem;
2
3 import java.io.*;
4
5 import com.daffodilwoods.database.resource.*;
6
7 public class BlobOutPutStream {
8
9   public int lastIndex;
10   private String JavaDoc path;
11
12   public BlobOutPutStream(String JavaDoc blobFileHome0) {
13     path = blobFileHome0+"blob.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("DSE5552", null);
32     }
33     catch (IOException ex) {
34       throw new DException("DSE5555", null);
35     }
36   }
37
38   public long getLength() {
39     File file = new File(path);
40     try {
41       if (file.exists()) {
42
43         FileInputStream fis = new FileInputStream(path);
44         lastIndex = fis.available();
45         fis.close() ;
46         return lastIndex;
47       }
48       return 0;
49     }
50     catch (IOException ex) {
51       return 0;
52     }
53   }
54   /*public static void main(String[] args) {
55     try {
56       path = "c:/daffodildbhome/test1/blob.lob";
57       FileInputStream fis = new FileInputStream(new File(path));
58       BlobSaveMode bsm = new BlobSaveMode(0,3977);
59       bsm.getBytes(0,3977);
60     }
61     catch (Exception ex) {
62     }
63   }*/

64 }
65
Popular Tags