2
|
1 |
/*
|
|
2 |
* Copyright 1999-2001 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 |
*
|
|
5 |
* This code is free software; you can redistribute it and/or modify it
|
|
6 |
* under the terms of the GNU General Public License version 2 only, as
|
|
7 |
* published by the Free Software Foundation. Sun designates this
|
|
8 |
* particular file as subject to the "Classpath" exception as provided
|
|
9 |
* by Sun in the LICENSE file that accompanied this code.
|
|
10 |
*
|
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT
|
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that
|
|
15 |
* accompanied this code).
|
|
16 |
*
|
|
17 |
* You should have received a copy of the GNU General Public License version
|
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation,
|
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
20 |
*
|
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or
|
|
23 |
* have any questions.
|
|
24 |
*/
|
|
25 |
|
|
26 |
package javax.imageio.stream;
|
|
27 |
|
|
28 |
/**
|
|
29 |
* A class representing a mutable reference to an array of bytes and
|
|
30 |
* an offset and length within that array. <code>IIOByteBuffer</code>
|
|
31 |
* is used by <code>ImageInputStream</code> to supply a sequence of bytes
|
|
32 |
* to the caller, possibly with fewer copies than using the conventional
|
|
33 |
* <code>read</code> methods that take a user-supplied byte array.
|
|
34 |
*
|
|
35 |
* <p> The byte array referenced by an <code>IIOByteBuffer</code> will
|
|
36 |
* generally be part of an internal data structure belonging to an
|
|
37 |
* <code>ImageReader</code> implementation; its contents should be
|
|
38 |
* considered read-only and must not be modified.
|
|
39 |
*
|
|
40 |
*/
|
|
41 |
public class IIOByteBuffer {
|
|
42 |
|
|
43 |
private byte[] data;
|
|
44 |
|
|
45 |
private int offset;
|
|
46 |
|
|
47 |
private int length;
|
|
48 |
|
|
49 |
/**
|
|
50 |
* Constructs an <code>IIOByteBuffer</code> that references a
|
|
51 |
* given byte array, offset, and length.
|
|
52 |
*
|
|
53 |
* @param data a byte array.
|
|
54 |
* @param offset an int offset within the array.
|
|
55 |
* @param length an int specifying the length of the data of
|
|
56 |
* interest within byte array, in bytes.
|
|
57 |
*/
|
|
58 |
public IIOByteBuffer(byte[] data, int offset, int length) {
|
|
59 |
this.data = data;
|
|
60 |
this.offset = offset;
|
|
61 |
this.length = length;
|
|
62 |
}
|
|
63 |
|
|
64 |
/**
|
|
65 |
* Returns a reference to the byte array. The returned value should
|
|
66 |
* be treated as read-only, and only the portion specified by the
|
|
67 |
* values of <code>getOffset</code> and <code>getLength</code> should
|
|
68 |
* be used.
|
|
69 |
*
|
|
70 |
* @return a byte array reference.
|
|
71 |
*
|
|
72 |
* @see #getOffset
|
|
73 |
* @see #getLength
|
|
74 |
* @see #setData
|
|
75 |
*/
|
|
76 |
public byte[] getData() {
|
|
77 |
return data;
|
|
78 |
}
|
|
79 |
|
|
80 |
/**
|
|
81 |
* Updates the array reference that will be returned by subsequent calls
|
|
82 |
* to the <code>getData</code> method.
|
|
83 |
*
|
|
84 |
* @param data a byte array reference containing the new data value.
|
|
85 |
*
|
|
86 |
* @see #getData
|
|
87 |
*/
|
|
88 |
public void setData(byte[] data) {
|
|
89 |
this.data = data;
|
|
90 |
}
|
|
91 |
|
|
92 |
/**
|
|
93 |
* Returns the offset within the byte array returned by
|
|
94 |
* <code>getData</code> at which the data of interest start.
|
|
95 |
*
|
|
96 |
* @return an int offset.
|
|
97 |
*
|
|
98 |
* @see #getData
|
|
99 |
* @see #getLength
|
|
100 |
* @see #setOffset
|
|
101 |
*/
|
|
102 |
public int getOffset() {
|
|
103 |
return offset;
|
|
104 |
}
|
|
105 |
|
|
106 |
/**
|
|
107 |
* Updates the value that will be returned by subsequent calls
|
|
108 |
* to the <code>getOffset</code> method.
|
|
109 |
*
|
|
110 |
* @param offset an int containing the new offset value.
|
|
111 |
*
|
|
112 |
* @see #getOffset
|
|
113 |
*/
|
|
114 |
public void setOffset(int offset) {
|
|
115 |
this.offset = offset;
|
|
116 |
}
|
|
117 |
|
|
118 |
/**
|
|
119 |
* Returns the length of the data of interest within the byte
|
|
120 |
* array returned by <code>getData</code>.
|
|
121 |
*
|
|
122 |
* @return an int length.
|
|
123 |
*
|
|
124 |
* @see #getData
|
|
125 |
* @see #getOffset
|
|
126 |
* @see #setLength
|
|
127 |
*/
|
|
128 |
public int getLength() {
|
|
129 |
return length;
|
|
130 |
}
|
|
131 |
|
|
132 |
/**
|
|
133 |
* Updates the value that will be returned by subsequent calls
|
|
134 |
* to the <code>getLength</code> method.
|
|
135 |
*
|
|
136 |
* @param length an int containing the new length value.
|
|
137 |
*
|
|
138 |
* @see #getLength
|
|
139 |
*/
|
|
140 |
public void setLength(int length) {
|
|
141 |
this.length = length;
|
|
142 |
}
|
|
143 |
}
|