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 protected AbstractRandomAccessStreamContent(final RandomAccessMode mode) { 030 super(mode); 031 } 032 033 protected abstract DataInputStream getDataInputStream() throws IOException; 034 035 @Override 036 public byte readByte() throws IOException { 037 return getDataInputStream().readByte(); 038 } 039 040 @Override 041 public char readChar() throws IOException { 042 return getDataInputStream().readChar(); 043 } 044 045 @Override 046 public double readDouble() throws IOException { 047 return getDataInputStream().readDouble(); 048 } 049 050 @Override 051 public float readFloat() throws IOException { 052 return getDataInputStream().readFloat(); 053 } 054 055 @Override 056 public int readInt() throws IOException { 057 return getDataInputStream().readInt(); 058 } 059 060 @Override 061 public int readUnsignedByte() throws IOException { 062 return getDataInputStream().readUnsignedByte(); 063 } 064 065 @Override 066 public int readUnsignedShort() throws IOException { 067 return getDataInputStream().readUnsignedShort(); 068 } 069 070 @Override 071 public long readLong() throws IOException { 072 return getDataInputStream().readLong(); 073 } 074 075 @Override 076 public short readShort() throws IOException { 077 return getDataInputStream().readShort(); 078 } 079 080 @Override 081 public boolean readBoolean() throws IOException { 082 return getDataInputStream().readBoolean(); 083 } 084 085 @Override 086 public int skipBytes(final int n) throws IOException { 087 return getDataInputStream().skipBytes(n); 088 } 089 090 @Override 091 public void readFully(final byte[] b) throws IOException { 092 getDataInputStream().readFully(b); 093 } 094 095 @Override 096 public void readFully(final byte[] b, final int off, final int len) throws IOException { 097 getDataInputStream().readFully(b, off, len); 098 } 099 100 @Override 101 public String readUTF() throws IOException { 102 return getDataInputStream().readUTF(); 103 } 104 105 @Override 106 public InputStream getInputStream() throws IOException { 107 return getDataInputStream(); 108 } 109 110 @Override 111 public void setLength(final long newLength) throws IOException { 112 throw new UnsupportedOperationException(); 113 } 114}