Path: blob/master/src/java.desktop/share/classes/javax/imageio/stream/IIOByteBuffer.java
41153 views
/*1* Copyright (c) 1999, 2001, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package javax.imageio.stream;2627/**28* A class representing a mutable reference to an array of bytes and29* an offset and length within that array. {@code IIOByteBuffer}30* is used by {@code ImageInputStream} to supply a sequence of bytes31* to the caller, possibly with fewer copies than using the conventional32* {@code read} methods that take a user-supplied byte array.33*34* <p> The byte array referenced by an {@code IIOByteBuffer} will35* generally be part of an internal data structure belonging to an36* {@code ImageReader} implementation; its contents should be37* considered read-only and must not be modified.38*39*/40public class IIOByteBuffer {4142private byte[] data;4344private int offset;4546private int length;4748/**49* Constructs an {@code IIOByteBuffer} that references a50* given byte array, offset, and length.51*52* @param data a byte array.53* @param offset an int offset within the array.54* @param length an int specifying the length of the data of55* interest within byte array, in bytes.56*/57public IIOByteBuffer(byte[] data, int offset, int length) {58this.data = data;59this.offset = offset;60this.length = length;61}6263/**64* Returns a reference to the byte array. The returned value should65* be treated as read-only, and only the portion specified by the66* values of {@code getOffset} and {@code getLength} should67* be used.68*69* @return a byte array reference.70*71* @see #getOffset72* @see #getLength73* @see #setData74*/75public byte[] getData() {76return data;77}7879/**80* Updates the array reference that will be returned by subsequent calls81* to the {@code getData} method.82*83* @param data a byte array reference containing the new data value.84*85* @see #getData86*/87public void setData(byte[] data) {88this.data = data;89}9091/**92* Returns the offset within the byte array returned by93* {@code getData} at which the data of interest start.94*95* @return an int offset.96*97* @see #getData98* @see #getLength99* @see #setOffset100*/101public int getOffset() {102return offset;103}104105/**106* Updates the value that will be returned by subsequent calls107* to the {@code getOffset} method.108*109* @param offset an int containing the new offset value.110*111* @see #getOffset112*/113public void setOffset(int offset) {114this.offset = offset;115}116117/**118* Returns the length of the data of interest within the byte119* array returned by {@code getData}.120*121* @return an int length.122*123* @see #getData124* @see #getOffset125* @see #setLength126*/127public int getLength() {128return length;129}130131/**132* Updates the value that will be returned by subsequent calls133* to the {@code getLength} method.134*135* @param length an int containing the new length value.136*137* @see #getLength138*/139public void setLength(int length) {140this.length = length;141}142}143144145