KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > javax > imageio > stream > IIOByteBuffer


1 /*
2  * @(#)IIOByteBuffer.java 1.14 03/12/19
3  *
4  * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
5  * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
6  */

7
8 package javax.imageio.stream;
9
10 /**
11  * A class representing a mutable reference to an array of bytes and
12  * an offset and length within that array. <code>IIOByteBuffer</code>
13  * is used by <code>ImageInputStream</code> to supply a sequence of bytes
14  * to the caller, possibly with fewer copies than using the conventional
15  * <code>read</code> methods that take a user-supplied byte array.
16  *
17  * <p> The byte array referenced by an <code>IIOByteBuffer</code> will
18  * generally be part of an internal data structure belonging to an
19  * <code>ImageReader</code> implementation; its contents should be
20  * considered read-only and must not be modified.
21  *
22  * @version 0.5
23  */

24 public class IIOByteBuffer {
25
26     private byte[] data;
27
28     private int offset;
29
30     private int length;
31
32     /**
33      * Constructs an <code>IIOByteBuffer</code> that references a
34      * given byte array, offset, and length.
35      *
36      * @param data a byte array.
37      * @param offset an int offset within the array.
38      * @param length an int specifying the length of the data of
39      * interest within byte array, in bytes.
40      */

41     public IIOByteBuffer(byte[] data, int offset, int length) {
42         this.data = data;
43         this.offset = offset;
44         this.length = length;
45     }
46
47     /**
48      * Returns a reference to the byte array. The returned value should
49      * be treated as read-only, and only the portion specified by the
50      * values of <code>getOffset</code> and <code>getLength</code> should
51      * be used.
52      *
53      * @return a byte array reference.
54      *
55      * @see #getOffset
56      * @see #getLength
57      * @see #setData
58      */

59     public byte[] getData() {
60         return data;
61     }
62
63     /**
64      * Updates the array reference that will be returned by subsequent calls
65      * to the <code>getData</code> method.
66      *
67      * @param data a byte array reference containing the new data value.
68      *
69      * @see #getData
70      */

71     public void setData(byte[] data) {
72         this.data = data;
73     }
74
75     /**
76      * Returns the offset within the byte array returned by
77      * <code>getData</code> at which the data of interest start.
78      *
79      * @return an int offset.
80      *
81      * @see #getData
82      * @see #getLength
83      * @see #setOffset
84      */

85     public int getOffset() {
86         return offset;
87     }
88
89     /**
90      * Updates the value that will be returned by subsequent calls
91      * to the <code>getOffset</code> method.
92      *
93      * @param offset an int containing the new offset value.
94      *
95      * @see #getOffset
96      */

97     public void setOffset(int offset) {
98         this.offset = offset;
99     }
100
101     /**
102      * Returns the length of the data of interest within the byte
103      * array returned by <code>getData</code>.
104      *
105      * @return an int length.
106      *
107      * @see #getData
108      * @see #getOffset
109      * @see #setLength
110      */

111     public int getLength() {
112         return length;
113     }
114
115     /**
116      * Updates the value that will be returned by subsequent calls
117      * to the <code>getLength</code> method.
118      *
119      * @param length an int containing the new length value.
120      *
121      * @see #getLength
122      */

123     public void setLength(int length) {
124         this.length = length;
125     }
126 }
127
Popular Tags