KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > ozoneDB > blob > BLOBPageImpl


1 // You can redistribute this software and/or modify it under the terms of
2
// the Ozone Library License version 1 published by ozone-db.org.
3
//
4
// The original code and portions created by SMB are
5
// Copyright (C) 1997-@year@ by SMB GmbH. All rights reserved.
6
//
7
// $Id: BLOBPageImpl.java,v 1.3 2002/12/29 11:15:55 per_nyfelt Exp $
8

9 package org.ozoneDB.blob;
10
11 import org.ozoneDB.OzoneObject;
12
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.3 $Date: 2002/12/29 11:15:55 $
20  */

21 public class BLOBPageImpl extends OzoneObject implements BLOBPage {
22     
23     byte[] data;
24     int space;
25     int size;
26     
27     
28     public BLOBPageImpl() {
29     }
30     
31     
32     public void init( int _space ) {
33         space = _space;
34         data = new byte[space];
35         size = 0;
36     }
37     
38     
39     public int size() {
40         return size;
41     }
42     
43     
44     /** */
45     public void write( byte[] b, int off ) {
46         if (off == 0 && b.length == space) {
47             data = b;
48             size = space;
49         } else {
50             int len = b.length;
51             // calculate the real length: 0 <= len <= (space-off)
52
len = Math.max( Math.min( space - off, len ), 0 );
53             
54             System.arraycopy( b, 0, data, off, len );
55             size = off + len;
56         }
57     }
58     
59     
60     /** */
61     public byte[] read( int off, int len ) {
62         // calculate the real length: 0 <= len <= (size-off)
63
len = Math.max( Math.min( size - off, len ), 0 );
64         
65         byte[] result = new byte[len];
66         System.arraycopy( data, off, result, 0, len );
67         
68         //////////////////////////////////////////////////////
69
//System.out.println ("return an array with length "+result.length);
70

71         return result;
72     }
73     
74 }
75
Popular Tags