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      {
32          super(mode);
33      }
34  
35      protected abstract DataInputStream getDataInputStream() throws IOException;
36  
37      @Override
38      public byte readByte() throws IOException
39      {
40          return getDataInputStream().readByte();
41      }
42  
43      @Override
44      public char readChar() throws IOException
45      {
46          return getDataInputStream().readChar();
47      }
48  
49      @Override
50      public double readDouble() throws IOException
51      {
52          return getDataInputStream().readDouble();
53      }
54  
55      @Override
56      public float readFloat() throws IOException
57      {
58          return getDataInputStream().readFloat();
59      }
60  
61      @Override
62      public int readInt() throws IOException
63      {
64          return getDataInputStream().readInt();
65      }
66  
67      @Override
68      public int readUnsignedByte() throws IOException
69      {
70          return getDataInputStream().readUnsignedByte();
71      }
72  
73      @Override
74      public int readUnsignedShort() throws IOException
75      {
76          return getDataInputStream().readUnsignedShort();
77      }
78  
79      @Override
80      public long readLong() throws IOException
81      {
82          return getDataInputStream().readLong();
83      }
84  
85      @Override
86      public short readShort() throws IOException
87      {
88          return getDataInputStream().readShort();
89      }
90  
91      @Override
92      public boolean readBoolean() throws IOException
93      {
94          return getDataInputStream().readBoolean();
95      }
96  
97      @Override
98      public int skipBytes(final int n) throws IOException
99      {
100         return getDataInputStream().skipBytes(n);
101     }
102 
103     @Override
104     public void readFully(final byte[] b) throws IOException
105     {
106         getDataInputStream().readFully(b);
107     }
108 
109     @Override
110     public void readFully(final byte[] b, final int off, final int len) throws IOException
111     {
112         getDataInputStream().readFully(b, off, len);
113     }
114 
115     @Override
116     public String readUTF() throws IOException
117     {
118         return getDataInputStream().readUTF();
119     }
120 
121     @Override
122     public InputStream getInputStream() throws IOException
123     {
124         return getDataInputStream();
125     }
126 
127     @Override
128     public void setLength(final long newLength) throws IOException
129     {
130         throw new UnsupportedOperationException();
131     }
132 }