View Javadoc
1   /*
2    * Copyright (C) 2012, Google Inc. and others
3    *
4    * This program and the accompanying materials are made available under the
5    * terms of the Eclipse Distribution License v. 1.0 which is available at
6    * https://www.eclipse.org/org/documents/edl-v10.php.
7    *
8    * SPDX-License-Identifier: BSD-3-Clause
9    */
10  
11  package org.eclipse.jgit.internal.storage.file;
12  
13  import java.io.DataInput;
14  import java.io.IOException;
15  import java.io.InputStream;
16  
17  import org.eclipse.jgit.util.IO;
18  import org.eclipse.jgit.util.NB;
19  
20  /**
21   * An implementation of DataInput that only handles readInt() and readLong()
22   * using the Git conversion utilities for network byte order handling. This is
23   * needed to read {@link com.googlecode.javaewah.EWAHCompressedBitmap}s.
24   */
25  class SimpleDataInput implements DataInput {
26  	private final InputStream fd;
27  
28  	private final byte[] buf = new byte[8];
29  
30  	SimpleDataInput(InputStream fd) {
31  		this.fd = fd;
32  	}
33  
34  	/** {@inheritDoc} */
35  	@Override
36  	public int readInt() throws IOException {
37  		readFully(buf, 0, 4);
38  		return NB.decodeInt32(buf, 0);
39  	}
40  
41  	/** {@inheritDoc} */
42  	@Override
43  	public long readLong() throws IOException {
44  		readFully(buf, 0, 8);
45  		return NB.decodeInt64(buf, 0);
46  	}
47  
48  	/**
49  	 * Read unsigned int
50  	 *
51  	 * @return a long.
52  	 * @throws java.io.IOException
53  	 *             if any.
54  	 */
55  	public long readUnsignedInt() throws IOException {
56  		readFully(buf, 0, 4);
57  		return NB.decodeUInt32(buf, 0);
58  	}
59  
60  	/** {@inheritDoc} */
61  	@Override
62  	public void readFully(byte[] b) throws IOException {
63  		readFully(b, 0, b.length);
64  	}
65  
66  	/** {@inheritDoc} */
67  	@Override
68  	public void readFully(byte[] b, int off, int len) throws IOException {
69  		IO.readFully(fd, b, off, len);
70  	}
71  
72  	/** {@inheritDoc} */
73  	@Override
74  	public int skipBytes(int n) throws IOException {
75  		throw new UnsupportedOperationException();
76  	}
77  
78  	/** {@inheritDoc} */
79  	@Override
80  	public boolean readBoolean() throws IOException {
81  		throw new UnsupportedOperationException();
82  	}
83  
84  	/** {@inheritDoc} */
85  	@Override
86  	public byte readByte() throws IOException {
87  		throw new UnsupportedOperationException();
88  	}
89  
90  	/** {@inheritDoc} */
91  	@Override
92  	public int readUnsignedByte() throws IOException {
93  		throw new UnsupportedOperationException();
94  	}
95  
96  	/** {@inheritDoc} */
97  	@Override
98  	public short readShort() throws IOException {
99  		throw new UnsupportedOperationException();
100 	}
101 
102 	/** {@inheritDoc} */
103 	@Override
104 	public int readUnsignedShort() throws IOException {
105 		throw new UnsupportedOperationException();
106 	}
107 
108 	/** {@inheritDoc} */
109 	@Override
110 	public char readChar() throws IOException {
111 		throw new UnsupportedOperationException();
112 	}
113 
114 	/** {@inheritDoc} */
115 	@Override
116 	public float readFloat() throws IOException {
117 		throw new UnsupportedOperationException();
118 	}
119 
120 	/** {@inheritDoc} */
121 	@Override
122 	public double readDouble() throws IOException {
123 		throw new UnsupportedOperationException();
124 	}
125 
126 	/** {@inheritDoc} */
127 	@Override
128 	public String readLine() throws IOException {
129 		throw new UnsupportedOperationException();
130 	}
131 
132 	/** {@inheritDoc} */
133 	@Override
134 	public String readUTF() throws IOException {
135 		throw new UnsupportedOperationException();
136 	}
137 }