package com.cloudera.util;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
private final ByteBuffer buf;
this.buf = buf.asReadOnlyBuffer();
}
@Override
public int read()
throws IOException {
try {
return buf.get();
} catch (BufferUnderflowException e) {
throw new EOFException();
}
}
@Override
public int read(
byte[] bytes,
int off,
int len)
throws IOException {
len = Math.min(len, buf.remaining());
try {
buf.get(bytes, off, len);
} catch (BufferUnderflowException e) {
throw new EOFException();
}
return len;
}
@Override
return buf.remaining();
}
}