KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.daffodilwoods.daffodildb.server.serversystem;
2
3 import java.io.*;
4 import java.sql.*;
5
6 import com.daffodilwoods.database.resource.*;
7
8 public class BlobSaveMode implements Blob {
9
10   private long start;
11   private int length;
12   private String JavaDoc savedlobFilePath;
13
14   public BlobSaveMode(long start0, int length0, String JavaDoc savedlobFilePath0) throws DException {
15     start = start0;
16     length = length0;
17     savedlobFilePath = savedlobFilePath0+"blob.lob";
18   }
19
20   public long length() throws SQLException {
21     return length;
22   }
23
24   public byte[] getBytes(long pos, int length0) throws SQLException {
25
26     long start1 = start + pos;
27     length0 = ( start1 + length0) < (start + length) ?
28               length0 + (int)start1 : (int)(length - pos );
29     byte[] buf = new byte[ length0];
30     int lengthRead =0;
31     long skip = -1;
32     try {
33       InputStream is = new FileInputStream(new File(savedlobFilePath));
34       if(start1!=0)
35         skip = is.skip(start1);
36       lengthRead = is.read(buf,0,length0);
37     }
38     catch (IOException ex) {
39       throw new SQLException(ex.getMessage());
40     }
41     return buf;
42   }
43
44   public InputStream getBinaryStream() throws SQLException {
45     return new ByteArrayInputStream(getBytes(0,length));
46   }
47   public long position(byte[] pattern, long start) throws SQLException {
48     /**@todo Implement this java.sql.Blob method*/
49     throw new java.lang.UnsupportedOperationException JavaDoc("Method position() not yet implemented.");
50   }
51   public long position(Blob pattern, long start) throws SQLException {
52     /**@todo Implement this java.sql.Blob method*/
53     throw new java.lang.UnsupportedOperationException JavaDoc("Method position() not yet implemented.");
54   }
55   public int setBytes(long pos, byte[] bytes) throws SQLException {
56     /**@todo Implement this java.sql.Blob method*/
57     throw new java.lang.UnsupportedOperationException JavaDoc("Method setBytes() not yet implemented.");
58   }
59   public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException {
60     /**@todo Implement this java.sql.Blob method*/
61     throw new java.lang.UnsupportedOperationException JavaDoc("Method setBytes() not yet implemented.");
62   }
63   public OutputStream setBinaryStream(long pos) throws SQLException {
64     /**@todo Implement this java.sql.Blob method*/
65     throw new java.lang.UnsupportedOperationException JavaDoc("Method setBinaryStream() not yet implemented.");
66   }
67   public void truncate(long len) throws SQLException {
68     /**@todo Implement this java.sql.Blob method*/
69     throw new java.lang.UnsupportedOperationException JavaDoc("Method truncate() not yet implemented.");
70   }
71 }
72
Popular Tags