001/*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements.  See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License.  You may obtain a copy of the License at
008 *
009 *      http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.apache.commons.vfs2.provider;
018
019import java.io.DataInputStream;
020import java.io.IOException;
021import java.io.InputStream;
022
023import org.apache.commons.vfs2.util.RandomAccessMode;
024
025/**
026 * Implements the part usable for all stream-based random access.
027 */
028public abstract class AbstractRandomAccessStreamContent extends AbstractRandomAccessContent {
029
030    /**
031     * Constructs a new instance for subclasses.
032     *
033     * @param mode the RandomAccessMode.
034     */
035    protected AbstractRandomAccessStreamContent(final RandomAccessMode mode) {
036        super(mode);
037    }
038
039    /**
040     * Gets a DataInputStream.
041     *
042     * @return a DataInputStream.
043     * @throws IOException if an IO error occurs.
044     */
045    protected abstract DataInputStream getDataInputStream() throws IOException;
046
047    @Override
048    public InputStream getInputStream() throws IOException {
049        return getDataInputStream();
050    }
051
052    @Override
053    public boolean readBoolean() throws IOException {
054        return getDataInputStream().readBoolean();
055    }
056
057    @Override
058    public byte readByte() throws IOException {
059        return getDataInputStream().readByte();
060    }
061
062    @Override
063    public char readChar() throws IOException {
064        return getDataInputStream().readChar();
065    }
066
067    @Override
068    public double readDouble() throws IOException {
069        return getDataInputStream().readDouble();
070    }
071
072    @Override
073    public float readFloat() throws IOException {
074        return getDataInputStream().readFloat();
075    }
076
077    @Override
078    public void readFully(final byte[] b) throws IOException {
079        getDataInputStream().readFully(b);
080    }
081
082    @Override
083    public void readFully(final byte[] b, final int off, final int len) throws IOException {
084        getDataInputStream().readFully(b, off, len);
085    }
086
087    @Override
088    public int readInt() throws IOException {
089        return getDataInputStream().readInt();
090    }
091
092    @Override
093    public long readLong() throws IOException {
094        return getDataInputStream().readLong();
095    }
096
097    @Override
098    public short readShort() throws IOException {
099        return getDataInputStream().readShort();
100    }
101
102    @Override
103    public int readUnsignedByte() throws IOException {
104        return getDataInputStream().readUnsignedByte();
105    }
106
107    @Override
108    public int readUnsignedShort() throws IOException {
109        return getDataInputStream().readUnsignedShort();
110    }
111
112    @Override
113    public String readUTF() throws IOException {
114        return getDataInputStream().readUTF();
115    }
116
117    @Override
118    public void setLength(final long newLength) throws IOException {
119        throw new UnsupportedOperationException();
120    }
121
122    @Override
123    public int skipBytes(final int n) throws IOException {
124        return getDataInputStream().skipBytes(n);
125    }
126}