View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one or more
3    * contributor license agreements.  See the NOTICE file distributed with
4    * this work for additional information regarding copyright ownership.
5    * The ASF licenses this file to You under the Apache License, Version 2.0
6    * (the "License"); you may not use this file except in compliance with
7    * the License.  You may obtain a copy of the License at
8    *
9    *      http://www.apache.org/licenses/LICENSE-2.0
10   *
11   * Unless required by applicable law or agreed to in writing, software
12   * distributed under the License is distributed on an "AS IS" BASIS,
13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14   * See the License for the specific language governing permissions and
15   * limitations under the License.
16   */
17  package org.apache.commons.vfs2.provider;
18  
19  import java.io.DataInputStream;
20  import java.io.IOException;
21  import java.io.InputStream;
22  
23  import org.apache.commons.vfs2.util.RandomAccessMode;
24  
25  /**
26   * Implements the part usable for all stream-based random access.
27   */
28  public abstract class AbstractRandomAccessStreamContent extends AbstractRandomAccessContent {
29  
30      protected AbstractRandomAccessStreamContent(final RandomAccessMode mode) {
31          super(mode);
32      }
33  
34      protected abstract DataInputStream getDataInputStream() throws IOException;
35  
36      @Override
37      public byte readByte() throws IOException {
38          return getDataInputStream().readByte();
39      }
40  
41      @Override
42      public char readChar() throws IOException {
43          return getDataInputStream().readChar();
44      }
45  
46      @Override
47      public double readDouble() throws IOException {
48          return getDataInputStream().readDouble();
49      }
50  
51      @Override
52      public float readFloat() throws IOException {
53          return getDataInputStream().readFloat();
54      }
55  
56      @Override
57      public int readInt() throws IOException {
58          return getDataInputStream().readInt();
59      }
60  
61      @Override
62      public int readUnsignedByte() throws IOException {
63          return getDataInputStream().readUnsignedByte();
64      }
65  
66      @Override
67      public int readUnsignedShort() throws IOException {
68          return getDataInputStream().readUnsignedShort();
69      }
70  
71      @Override
72      public long readLong() throws IOException {
73          return getDataInputStream().readLong();
74      }
75  
76      @Override
77      public short readShort() throws IOException {
78          return getDataInputStream().readShort();
79      }
80  
81      @Override
82      public boolean readBoolean() throws IOException {
83          return getDataInputStream().readBoolean();
84      }
85  
86      @Override
87      public int skipBytes(final int n) throws IOException {
88          return getDataInputStream().skipBytes(n);
89      }
90  
91      @Override
92      public void readFully(final byte[] b) throws IOException {
93          getDataInputStream().readFully(b);
94      }
95  
96      @Override
97      public void readFully(final byte[] b, final int off, final int len) throws IOException {
98          getDataInputStream().readFully(b, off, len);
99      }
100 
101     @Override
102     public String readUTF() throws IOException {
103         return getDataInputStream().readUTF();
104     }
105 
106     @Override
107     public InputStream getInputStream() throws IOException {
108         return getDataInputStream();
109     }
110 
111     @Override
112     public void setLength(final long newLength) throws IOException {
113         throw new UnsupportedOperationException();
114     }
115 }