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      /**
31       * Constructs a new instance for subclasses.
32       *
33       * @param mode the RandomAccessMode.
34       */
35      protected AbstractRandomAccessStreamContent(final RandomAccessMode mode) {
36          super(mode);
37      }
38  
39      /**
40       * Gets a DataInputStream.
41       *
42       * @return a DataInputStream.
43       * @throws IOException if an IO error occurs.
44       */
45      protected abstract DataInputStream getDataInputStream() throws IOException;
46  
47      @Override
48      public InputStream getInputStream() throws IOException {
49          return getDataInputStream();
50      }
51  
52      @Override
53      public boolean readBoolean() throws IOException {
54          return getDataInputStream().readBoolean();
55      }
56  
57      @Override
58      public byte readByte() throws IOException {
59          return getDataInputStream().readByte();
60      }
61  
62      @Override
63      public char readChar() throws IOException {
64          return getDataInputStream().readChar();
65      }
66  
67      @Override
68      public double readDouble() throws IOException {
69          return getDataInputStream().readDouble();
70      }
71  
72      @Override
73      public float readFloat() throws IOException {
74          return getDataInputStream().readFloat();
75      }
76  
77      @Override
78      public void readFully(final byte[] b) throws IOException {
79          getDataInputStream().readFully(b);
80      }
81  
82      @Override
83      public void readFully(final byte[] b, final int off, final int len) throws IOException {
84          getDataInputStream().readFully(b, off, len);
85      }
86  
87      @Override
88      public int readInt() throws IOException {
89          return getDataInputStream().readInt();
90      }
91  
92      @Override
93      public long readLong() throws IOException {
94          return getDataInputStream().readLong();
95      }
96  
97      @Override
98      public short readShort() throws IOException {
99          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 }