001: // ByteArrayIInStream.java
002: // -------------------------------------
003: // part of YACY
004: // (C) by Michael Peter Christen; mc@anomic.de
005: // first published on http://www.anomic.de
006: // Frankfurt, Germany, 2004
007: //
008: // This file ist contributed by Franz Brausze
009: //
010: // This program is free software; you can redistribute it and/or modify
011: // it under the terms of the GNU General Public License as published by
012: // the Free Software Foundation; either version 2 of the License, or
013: // (at your option) any later version.
014: //
015: // This program is distributed in the hope that it will be useful,
016: // but WITHOUT ANY WARRANTY; without even the implied warranty of
017: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
018: // GNU General Public License for more details.
019: //
020: // You should have received a copy of the GNU General Public License
021: // along with this program; if not, write to the Free Software
022: // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
023: //
024: // Using this software in any meaning (reading, learning, copying, compiling,
025: // running) means that you agree that the Author(s) is (are) not responsible
026: // for cost, loss of data or any harm that may be caused directly or indirectly
027: // by usage of this softare or this documentation. The usage of this software
028: // is on your own risk. The installation and usage (starting/running) of this
029: // software may allow other people or application to access your computer and
030: // any attached devices and is highly dependent on the configuration of the
031: // software which must be done by the user of the software; the author(s) is
032: // (are) also not responsible for proper configuration and usage of the
033: // software, even if provoked by documentation provided together with
034: // the software.
035: //
036: // Any changes to this file according to the GPL as documented in the file
037: // gpl.txt aside this file in the shipment you received can be done to the
038: // lines that follows this copyright notice here, but changes must not be
039: // done inside the copyright notive above. A re-distribution must contain
040: // the intact and unchanged copyright notice.
041: // Contributions and changes to the program code must be marked as such.
042:
043: package de.anomic.plasma.parser.sevenzip;
044:
045: import java.io.ByteArrayInputStream;
046: import java.io.IOException;
047:
048: import SevenZip.IInStream;
049:
050: public class ByteArrayIInStream extends IInStream {
051:
052: private class SeekableByteArrayInputStream extends
053: ByteArrayInputStream {
054: public SeekableByteArrayInputStream(byte[] buf) {
055: super (buf);
056: }
057:
058: public SeekableByteArrayInputStream(byte[] buf, int off, int len) {
059: super (buf, off, len);
060: }
061:
062: public int getPosition() {
063: return super .pos;
064: }
065:
066: public void seekRelative(int offset) {
067: seekAbsolute(super .pos + offset);
068: }
069:
070: public void seekAbsolute(int offset) {
071: if (offset > super .count)
072: throw new IndexOutOfBoundsException(Integer
073: .toString(offset));
074: super .pos = offset;
075: }
076: }
077:
078: private final SeekableByteArrayInputStream sbais;
079:
080: public ByteArrayIInStream(byte[] buffer) {
081: this .sbais = new SeekableByteArrayInputStream(buffer);
082: }
083:
084: public long Seek(long offset, int origin) {
085: switch (origin) {
086: case STREAM_SEEK_SET:
087: this .sbais.seekAbsolute((int) offset);
088: break;
089: case STREAM_SEEK_CUR:
090: this .sbais.seekRelative((int) offset);
091: break;
092: }
093: return this .sbais.getPosition();
094: }
095:
096: public int read() throws IOException {
097: return this .sbais.read();
098: }
099:
100: public int read(byte[] b, int off, int len) throws IOException {
101: return this.sbais.read(b, off, len);
102: }
103: }
|