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.File;
033: import java.io.FileNotFoundException;
034: import java.io.IOException;
035:
036: /**
037: * An interface to allow temp PDF data to be stored in a scratch
038: * file on the disk to reduce memory consumption.
039: *
040: * @author <a href="mailto:ben@benlitchfield.com">Ben Litchfield</a>
041: * @version $Revision: 1.2 $
042: */
043: public class RandomAccessFile implements RandomAccess {
044: private java.io.RandomAccessFile ras;
045:
046: /**
047: * Constructor.
048: *
049: * @param file The file to write the data to.
050: * @param mode The writing mode.
051: * @throws FileNotFoundException If the file cannot be created.
052: */
053: public RandomAccessFile(File file, String mode)
054: throws FileNotFoundException {
055: ras = new java.io.RandomAccessFile(file, mode);
056: }
057:
058: /**
059: * {@inheritDoc}
060: */
061: public void close() throws IOException {
062: ras.close();
063: }
064:
065: /**
066: * {@inheritDoc}
067: */
068: public void seek(long position) throws IOException {
069: ras.seek(position);
070: }
071:
072: /**
073: * {@inheritDoc}
074: */
075: public int read() throws IOException {
076: return ras.read();
077: }
078:
079: /**
080: * {@inheritDoc}
081: */
082: public int read(byte[] b, int offset, int length)
083: throws IOException {
084: return ras.read(b, offset, length);
085: }
086:
087: /**
088: * {@inheritDoc}
089: */
090: public long length() throws IOException {
091: return ras.length();
092: }
093:
094: /**
095: * {@inheritDoc}
096: */
097: public void write(byte[] b, int offset, int length)
098: throws IOException {
099: ras.write(b, offset, length);
100: }
101:
102: /**
103: * {@inheritDoc}
104: */
105: public void write(int b) throws IOException {
106: ras.write(b);
107: }
108: }
|