01: // You can redistribute this software and/or modify it under the terms of
02: // the Ozone Library License version 1 published by ozone-db.org.
03: //
04: // The original code and portions created by SMB are
05: // Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
06: //
07: // $Id: BLOBPageImpl.java,v 1.1 2001/12/18 10:31:30 per_nyfelt Exp $
08:
09: package org.ozoneDB.blob;
10:
11: import org.ozoneDB.*;
12: import java.io.*;
13:
14: /**
15: * One page of an ozone BLOB.
16: *
17: *
18: * @author <a href="http://www.softwarebuero.de/">SMB</a>
19: * @version $Revision: 1.1 $Date: 2001/12/18 10:31:30 $
20: */
21: public class BLOBPageImpl extends OzoneObject implements BLOBPage {
22:
23: byte[] data;
24: int space;
25: int size;
26:
27: public BLOBPageImpl() {
28: }
29:
30: public void init(int _space) {
31: space = _space;
32: data = new byte[space];
33: size = 0;
34: }
35:
36: public int size() {
37: return size;
38: }
39:
40: /** */
41: public void write(byte[] b, int off) {
42: if (off == 0 && b.length == space) {
43: data = b;
44: size = space;
45: } else {
46: int len = b.length;
47: // calculate the real length: 0 <= len <= (space-off)
48: len = Math.max(Math.min(space - off, len), 0);
49:
50: System.arraycopy(b, 0, data, off, len);
51: size = off + len;
52: }
53: }
54:
55: /** */
56: public byte[] read(int off, int len) {
57: // calculate the real length: 0 <= len <= (size-off)
58: len = Math.max(Math.min(size - off, len), 0);
59:
60: byte[] result = new byte[len];
61: System.arraycopy(data, off, result, 0, len);
62:
63: //////////////////////////////////////////////////////
64: //System.out.println ("return an array with length "+result.length);
65:
66: return result;
67: }
68:
69: }
|