1/*2 * Licensed to the Apache Software Foundation (ASF) under one3 * or more contributor license agreements. See the NOTICE file4 * distributed with this work for additional information5 * regarding copyright ownership. The ASF licenses this file6 * to you under the Apache License, Version 2.0 (the7 * "License"); you may not use this file except in compliance8 * with the License. You may obtain a copy of the License at9 *10 * http://www.apache.org/licenses/LICENSE-2.011 *12 * Unless required by applicable law or agreed to in writing, software13 * distributed under the License is distributed on an "AS IS" BASIS,14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.15 * See the License for the specific language governing permissions and16 * limitations under the License.17 */18package org.apache.giraph.writable.kryo;
1920import java.io.DataInput;
21import java.io.EOFException;
22import java.io.IOException;
23import java.io.InputStream;
2425/**26 * Thin wrapper around DataInput so it can be used as an27 * {@link java.io.InputStream}28 *29 * For use with {@link com.esotericsoftware.kryo.io.Input}30 */31publicclassDataInputWrapperStreamextends InputStream {
32/** Wrapped DataInput object */33private DataInput in;
3435publicvoid setDataInput(DataInput in) {
36this.in = in;
37 }
3839 @Override
40publicint read() throws IOException {
41try {
42return in.readByte() & 0xFF;
43 } catch (EOFException e) {
44thrownew RuntimeException(
45"Chunked input should never read more than chunked output wrote", e);
46 }
47 }
4849 @Override
50publicint read(byte[] b, int off, int len) throws IOException {
51try {
52 in.readFully(b, off, len);
53return len;
54 } catch (EOFException e) {
55thrownew RuntimeException(
56"Chunked input should never read more than chunked output wrote", e);
57 }
58 }
59 }