001: /**
002: * Copyright (c) 2006, www.pdfbox.org
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions are met:
007: *
008: * 1. Redistributions of source code must retain the above copyright notice,
009: * this list of conditions and the following disclaimer.
010: * 2. Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: * 3. Neither the name of pdfbox; nor the names of its
014: * contributors may be used to endorse or promote products derived from this
015: * software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
018: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
019: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
020: * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
021: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
022: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
023: * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
024: * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
025: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
026: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
027: *
028: * http://www.pdfbox.org
029: *
030: */package org.pdfbox.io;
031:
032: import java.io.IOException;
033:
034: /**
035: * An interface to allow PDF files to be stored completely in memory or
036: * to use a scratch file on the disk.
037: *
038: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
039: * @version $Revision: 1.2 $
040: */
041: public interface RandomAccess {
042:
043: /**
044: * Release resources that are being held.
045: *
046: * @throws IOException If there is an error closing this resource.
047: */
048: public void close() throws IOException;
049:
050: /**
051: * Seek to a position in the data.
052: *
053: * @param position The position to seek to.
054: * @throws IOException If there is an error while seeking.
055: */
056: public void seek(long position) throws IOException;
057:
058: /**
059: * Read a single byte of data.
060: *
061: * @return The byte of data that is being read.
062: *
063: * @throws IOException If there is an error while reading the data.
064: */
065: public int read() throws IOException;
066:
067: /**
068: * Read a buffer of data.
069: *
070: * @param b The buffer to write the data to.
071: * @param offset Offset into the buffer to start writing.
072: * @param length The amount of data to attempt to read.
073: * @return The number of bytes that were actually read.
074: * @throws IOException If there was an error while reading the data.
075: */
076: public int read(byte[] b, int offset, int length)
077: throws IOException;
078:
079: /**
080: * The total number of bytes that are available.
081: *
082: * @return The number of bytes available.
083: *
084: * @throws IOException If there is an IO error while determining the
085: * length of the data stream.
086: */
087: public long length() throws IOException;
088:
089: /**
090: * Write a byte to the stream.
091: *
092: * @param b The byte to write.
093: * @throws IOException If there is an IO error while writing.
094: */
095: public void write(int b) throws IOException;
096:
097: /**
098: * Write a buffer of data to the stream.
099: *
100: * @param b The buffer to get the data from.
101: * @param offset An offset into the buffer to get the data from.
102: * @param length The length of data to write.
103: * @throws IOException If there is an error while writing the data.
104: */
105: public void write(byte[] b, int offset, int length)
106: throws IOException;
107:
108: }
|