1 /*
2 * Copyright (C) 2012, Google Inc.
3 * and other copyright owners as documented in the project's IP log.
4 *
5 * This program and the accompanying materials are made available
6 * under the terms of the Eclipse Distribution License v1.0 which
7 * accompanies this distribution, is reproduced below, and is
8 * available at http://www.eclipse.org/org/documents/edl-v10.php
9 *
10 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or
13 * without modification, are permitted provided that the following
14 * conditions are met:
15 *
16 * - Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 *
19 * - Redistributions in binary form must reproduce the above
20 * copyright notice, this list of conditions and the following
21 * disclaimer in the documentation and/or other materials provided
22 * with the distribution.
23 *
24 * - Neither the name of the Eclipse Foundation, Inc. nor the
25 * names of its contributors may be used to endorse or promote
26 * products derived from this software without specific prior
27 * written permission.
28 *
29 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
30 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
31 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
32 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
34 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
36 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
37 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
38 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
40 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
41 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
42 */
43
44 package org.eclipse.jgit.internal.storage.file;
45
46 import java.io.DataInput;
47 import java.io.IOException;
48 import java.io.InputStream;
49
50 import org.eclipse.jgit.util.IO;
51 import org.eclipse.jgit.util.NB;
52
53 /**
54 * An implementation of DataInput that only handles readInt() and readLong()
55 * using the Git conversion utilities for network byte order handling. This is
56 * needed to read {@link com.googlecode.javaewah.EWAHCompressedBitmap}s.
57 */
58 class SimpleDataInput implements DataInput {
59 private final InputStream fd;
60
61 private final byte[] buf = new byte[8];
62
63 SimpleDataInput(InputStream fd) {
64 this.fd = fd;
65 }
66
67 /** {@inheritDoc} */
68 @Override
69 public int readInt() throws IOException {
70 readFully(buf, 0, 4);
71 return NB.decodeInt32(buf, 0);
72 }
73
74 /** {@inheritDoc} */
75 @Override
76 public long readLong() throws IOException {
77 readFully(buf, 0, 8);
78 return NB.decodeInt64(buf, 0);
79 }
80
81 /**
82 * Read unsigned int
83 *
84 * @return a long.
85 * @throws java.io.IOException
86 * if any.
87 */
88 public long readUnsignedInt() throws IOException {
89 readFully(buf, 0, 4);
90 return NB.decodeUInt32(buf, 0);
91 }
92
93 /** {@inheritDoc} */
94 @Override
95 public void readFully(byte[] b) throws IOException {
96 readFully(b, 0, b.length);
97 }
98
99 /** {@inheritDoc} */
100 @Override
101 public void readFully(byte[] b, int off, int len) throws IOException {
102 IO.readFully(fd, b, off, len);
103 }
104
105 /** {@inheritDoc} */
106 @Override
107 public int skipBytes(int n) throws IOException {
108 throw new UnsupportedOperationException();
109 }
110
111 /** {@inheritDoc} */
112 @Override
113 public boolean readBoolean() throws IOException {
114 throw new UnsupportedOperationException();
115 }
116
117 /** {@inheritDoc} */
118 @Override
119 public byte readByte() throws IOException {
120 throw new UnsupportedOperationException();
121 }
122
123 /** {@inheritDoc} */
124 @Override
125 public int readUnsignedByte() throws IOException {
126 throw new UnsupportedOperationException();
127 }
128
129 /** {@inheritDoc} */
130 @Override
131 public short readShort() throws IOException {
132 throw new UnsupportedOperationException();
133 }
134
135 /** {@inheritDoc} */
136 @Override
137 public int readUnsignedShort() throws IOException {
138 throw new UnsupportedOperationException();
139 }
140
141 /** {@inheritDoc} */
142 @Override
143 public char readChar() throws IOException {
144 throw new UnsupportedOperationException();
145 }
146
147 /** {@inheritDoc} */
148 @Override
149 public float readFloat() throws IOException {
150 throw new UnsupportedOperationException();
151 }
152
153 /** {@inheritDoc} */
154 @Override
155 public double readDouble() throws IOException {
156 throw new UnsupportedOperationException();
157 }
158
159 /** {@inheritDoc} */
160 @Override
161 public String readLine() throws IOException {
162 throw new UnsupportedOperationException();
163 }
164
165 /** {@inheritDoc} */
166 @Override
167 public String readUTF() throws IOException {
168 throw new UnsupportedOperationException();
169 }
170 }