001/* 002 * $RCSfile: RandomAccessIO.java,v $ 003 * $Revision: 1.1 $ 004 * $Date: 2005/02/11 05:02:16 $ 005 * $State: Exp $ 006 * 007 * Interface: RandomAccessIO.java 008 * 009 * Description: Interface definition for random access I/O. 010 * 011 * 012 * 013 * COPYRIGHT: 014 * 015 * This software module was originally developed by Raphaël Grosbois and 016 * Diego Santa Cruz (Swiss Federal Institute of Technology-EPFL); Joel 017 * Askelöf (Ericsson Radio Systems AB); and Bertrand Berthelot, David 018 * Bouchard, Félix Henry, Gerard Mozelle and Patrice Onno (Canon Research 019 * Centre France S.A) in the course of development of the JPEG2000 020 * standard as specified by ISO/IEC 15444 (JPEG 2000 Standard). This 021 * software module is an implementation of a part of the JPEG 2000 022 * Standard. Swiss Federal Institute of Technology-EPFL, Ericsson Radio 023 * Systems AB and Canon Research Centre France S.A (collectively JJ2000 024 * Partners) agree not to assert against ISO/IEC and users of the JPEG 025 * 2000 Standard (Users) any of their rights under the copyright, not 026 * including other intellectual property rights, for this software module 027 * with respect to the usage by ISO/IEC and Users of this software module 028 * or modifications thereof for use in hardware or software products 029 * claiming conformance to the JPEG 2000 Standard. Those intending to use 030 * this software module in hardware or software products are advised that 031 * their use may infringe existing patents. The original developers of 032 * this software module, JJ2000 Partners and ISO/IEC assume no liability 033 * for use of this software module or modifications thereof. No license 034 * or right to this software module is granted for non JPEG 2000 Standard 035 * conforming products. JJ2000 Partners have full right to use this 036 * software module for his/her own purpose, assign or donate this 037 * software module to any third party and to inhibit third parties from 038 * using this software module for non JPEG 2000 Standard conforming 039 * products. This copyright notice must be included in all copies or 040 * derivative works of this software module. 041 * 042 * Copyright (c) 1999/2000 JJ2000 Partners. 043 */ 044 045package jj2000.j2k.io; 046 047import java.io.EOFException; 048import java.io.IOException; 049 050/** 051 * This abstract class defines the interface to perform random access I/O. It 052 * implements the <tt>BinaryDataInput</tt> and <tt>BinaryDataOutput</tt> 053 * interfaces so that binary data input/output can be performed. 054 * 055 * <P>This interface supports streams of up to 2 GB in length. 056 * 057 * @see BinaryDataInput 058 * @see BinaryDataOutput 059 * */ 060public interface RandomAccessIO 061 extends BinaryDataInput, BinaryDataOutput { 062 063 /** 064 * Closes the I/O stream. Prior to closing the stream, any buffered data 065 * (at the bit and byte level) should be written. 066 * 067 * @exception IOException If an I/O error ocurred. 068 * */ 069 public void close() throws IOException; 070 071 /** 072 * Returns the current position in the stream, which is the position from 073 * where the next byte of data would be read. The first byte in the stream 074 * is in position <tt>0</tt>. 075 * 076 * @return The offset of the current position, in bytes. 077 * 078 * @exception IOException If an I/O error ocurred. 079 * */ 080 public int getPos() throws IOException; 081 082 /** 083 * Returns the current length of the stream, in bytes, taking into account 084 * any buffering. 085 * 086 * @return The length of the stream, in bytes. 087 * 088 * @exception IOException If an I/O error ocurred. 089 * */ 090 public int length() throws IOException; 091 092 /** 093 * Moves the current position for the next read or write operation to 094 * offset. The offset is measured from the beginning of the stream. The 095 * offset may be set beyond the end of the file, if in write mode. Setting 096 * the offset beyond the end of the file does not change the file 097 * length. The file length will change only by writing after the offset 098 * has been set beyond the end of the file. 099 * 100 * @param off The offset where to move to. 101 * 102 * @exception EOFException If in read-only and seeking beyond EOF. 103 * 104 * @exception IOException If an I/O error ocurred. 105 * */ 106 public void seek(int off) throws IOException; 107 108 /** 109 * Reads a byte of data from the stream. Prior to reading, the stream is 110 * realigned at the byte level. 111 * 112 * @return The byte read, as an int. 113 * 114 * @exception EOFException If the end-of file was reached. 115 * 116 * @exception IOException If an I/O error ocurred. 117 * */ 118 public int read() throws EOFException, IOException; 119 120 /** 121 * Reads up to len bytes of data from this file into an array of 122 * bytes. This method reads repeatedly from the stream until all the bytes 123 * are read. This method blocks until all the bytes are read, the end of 124 * the stream is detected, or an exception is thrown. 125 * 126 * @param b The buffer into which the data is to be read. It must be long 127 * enough. 128 * 129 * @param off The index in 'b' where to place the first byte read. 130 * 131 * @param len The number of bytes to read. 132 * 133 * @exception EOFException If the end-of file was reached before 134 * getting all the necessary data. 135 * 136 * @exception IOException If an I/O error ocurred. 137 * */ 138 public void readFully(byte b[], int off, int len) throws IOException; 139 140 /** 141 * Writes a byte to the stream. Prior to writing, the stream is realigned 142 * at the byte level. 143 * 144 * @param b The byte to write. The lower 8 bits of <tt>b</tt> are 145 * written. 146 * 147 * @exception IOException If an I/O error ocurred. 148 * */ 149 public void write(int b) throws IOException; 150}