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