1. /*
  2. * @(#)IIOByteBuffer.java 1.13 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.imageio.stream;
  8. /**
  9. * A class representing a mutable reference to an array of bytes and
  10. * an offset and length within that array. <code>IIOByteBuffer</code>
  11. * is used by <code>ImageInputStream</code> to supply a sequence of bytes
  12. * to the caller, possibly with fewer copies than using the conventional
  13. * <code>read</code> methods that take a user-supplied byte array.
  14. *
  15. * <p> The byte array referenced by an <code>IIOByteBuffer</code> will
  16. * generally be part of an internal data structure belonging to an
  17. * <code>ImageReader</code> implementation; its contents should be
  18. * considered read-only and must not be modified.
  19. *
  20. * @version 0.5
  21. */
  22. public class IIOByteBuffer {
  23. private byte[] data;
  24. private int offset;
  25. private int length;
  26. /**
  27. * Constructs an <code>IIOByteBuffer</code> that references a
  28. * given byte array, offset, and length.
  29. *
  30. * @param data a byte array.
  31. * @param offset an int offset within the array.
  32. * @param length an int specifying the length of the data of
  33. * interest within byte array, in bytes.
  34. */
  35. public IIOByteBuffer(byte[] data, int offset, int length) {
  36. this.data = data;
  37. this.offset = offset;
  38. this.length = length;
  39. }
  40. /**
  41. * Returns a reference to the byte array. The returned value should
  42. * be treated as read-only, and only the portion specified by the
  43. * values of <code>getOffset</code> and <code>getLength</code> should
  44. * be used.
  45. *
  46. * @return a byte array reference.
  47. *
  48. * @see #getOffset
  49. * @see #getLength
  50. * @see #setData
  51. */
  52. public byte[] getData() {
  53. return data;
  54. }
  55. /**
  56. * Updates the array reference that will be returned by subsequent calls
  57. * to the <code>getData</code> method.
  58. *
  59. * @param data a byte array reference containing the new data value.
  60. *
  61. * @see #getData
  62. */
  63. public void setData(byte[] data) {
  64. this.data = data;
  65. }
  66. /**
  67. * Returns the offset within the byte array returned by
  68. * <code>getData</code> at which the data of interest start.
  69. *
  70. * @return an int offset.
  71. *
  72. * @see #getData
  73. * @see #getLength
  74. * @see #setOffset
  75. */
  76. public int getOffset() {
  77. return offset;
  78. }
  79. /**
  80. * Updates the value that will be returned by subsequent calls
  81. * to the <code>getOffset</code> method.
  82. *
  83. * @param offset an int containing the new offset value.
  84. *
  85. * @see #getOffset
  86. */
  87. public void setOffset(int offset) {
  88. this.offset = offset;
  89. }
  90. /**
  91. * Returns the length of the data of interest within the byte
  92. * array returned by <code>getData</code>.
  93. *
  94. * @return an int length.
  95. *
  96. * @see #getData
  97. * @see #getOffset
  98. * @see #setLength
  99. */
  100. public int getLength() {
  101. return length;
  102. }
  103. /**
  104. * Updates the value that will be returned by subsequent calls
  105. * to the <code>getLength</code> method.
  106. *
  107. * @param length an int containing the new length value.
  108. *
  109. * @see #getLength
  110. */
  111. public void setLength(int length) {
  112. this.length = length;
  113. }
  114. }