本文整理汇总了Java中java.io.EOFException类的典型用法代码示例。如果您正苦于以下问题:Java EOFException类的具体用法?Java EOFException怎么用?Java EOFException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
EOFException类属于java.io包,在下文中一共展示了EOFException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: readDelimitedBuffer
import java.io.EOFException; //导入依赖的package包/类
protected static byte[] readDelimitedBuffer(RandomAccessFile fileHandle)
throws IOException, CorruptEventException {
int length = fileHandle.readInt();
if (length < 0) {
throw new CorruptEventException("Length of event is: " + String.valueOf(length) +
". Event must have length >= 0. Possible corruption of data or partial fsync.");
}
byte[] buffer = new byte[length];
try {
fileHandle.readFully(buffer);
} catch (EOFException ex) {
throw new CorruptEventException("Remaining data in file less than " +
"expected size of event.", ex);
}
return buffer;
}
示例2: skipLines
import java.io.EOFException; //导入依赖的package包/类
/**
* Skip forward the number of line delimiters. If you are in the middle of a line,
* a value of 1 will skip to the start of the next record.
* @param lines Number of lines to skip.
* @throws IOException
*/
public final void skipLines(int lines) throws IOException {
if (lines < 1) {
return;
}
long expectedLineCount = this.lineCount + lines;
try {
do {
nextChar();
} while (lineCount < expectedLineCount);
if (lineCount < lines) {
throw new IllegalArgumentException("Unable to skip " + lines + " lines from line " + (expectedLineCount - lines) + ". End of input reached");
}
} catch (EOFException ex) {
throw new IllegalArgumentException("Unable to skip " + lines + " lines from line " + (expectedLineCount - lines) + ". End of input reached");
}
}
示例3: readAsciiLine
import java.io.EOFException; //导入依赖的package包/类
/**
* Returns the ASCII characters up to but not including the next "\r\n", or
* "\n".
*
* @throws java.io.EOFException if the stream is exhausted before the next newline
* character.
*/
public static String readAsciiLine(InputStream in) throws IOException {
// TODO: support UTF-8 here instead
StringBuilder result = new StringBuilder(80);
while (true) {
int c = in.read();
if (c == -1) {
throw new EOFException();
} else if (c == '\n') {
break;
}
result.append((char) c);
}
int length = result.length();
if (length > 0 && result.charAt(length - 1) == '\r') {
result.setLength(length - 1);
}
return result.toString();
}
示例4: parse
import java.io.EOFException; //导入依赖的package包/类
@Override
public GraphDocument parse() throws IOException {
folderStack.push(rootDocument);
hashStack.push(null);
if (monitor != null) {
monitor.setState("Starting parsing");
}
try {
while(true) {
parseRoot();
}
} catch (EOFException e) {
}
if (monitor != null) {
monitor.setState("Finished parsing");
}
return rootDocument;
}
示例5: readFully
import java.io.EOFException; //导入依赖的package包/类
@Override
public void readFully(long position, byte[] b, int off, int len)
throws IOException {
if (b == null) {
throw new NullPointerException();
} else if (off < 0 || len < 0 || len > b.length - off) {
throw new IndexOutOfBoundsException();
} else if (len == 0) {
return;
}
if (position > length) {
throw new IOException("Cannot read after EOF.");
}
if (position < 0) {
throw new IOException("Cannot read to negative offset.");
}
checkStream();
if (position + len > length) {
throw new EOFException("Reach the end of stream.");
}
System.arraycopy(data, (int)position, b, off, len);
}
示例6: write
import java.io.EOFException; //导入依赖的package包/类
@Override
public void write(byte[] b, int off, int len) throws IOException {
ByteBuffer bb = ByteBuffer.wrap(b, off, len);
while (bb.remaining() > 0) {
channel.write(bb);
if (bb.remaining() == 0) {
return;
}
// wait for socket to become ready again
int sel = selector.select(timeout);
if (sel == 0) {
throw new IOException("Timed out");
} else if (!channel.isConnected()) {
throw new EOFException("Closed");
}
}
}
示例7: readRow
import java.io.EOFException; //导入依赖的package包/类
boolean readRow(RowInputInterface rowin, int pos) throws IOException {
try {
int length = dataStreamIn.readInt();
int count = 4;
if (length == 0) {
return false;
}
rowin.resetRow(pos, length);
dataStreamIn.readFully(rowin.getBuffer(), count, length - count);
return true;
} catch (EOFException e) {
return false;
}
}
示例8: readAsciiLine
import java.io.EOFException; //导入依赖的package包/类
/**
* Returns the ASCII characters up to but not including the next "\r\n", or
* "\n".
*
* @throws EOFException if the stream is exhausted before the next newline
* character.
*/
public static String readAsciiLine(InputStream in) throws IOException {
// TODO: support UTF-8 here instead
StringBuilder result = new StringBuilder(80);
while (true) {
int c = in.read();
if (c == -1) {
throw new EOFException();
} else if (c == '\n') {
break;
}
result.append((char) c);
}
int length = result.length();
if (length > 0 && result.charAt(length - 1) == '\r') {
result.setLength(length - 1);
}
return result.toString();
}
示例9: readAsciiLine
import java.io.EOFException; //导入依赖的package包/类
/**
* Returns the ASCII characters up to but not including the next "\r\n", or
* "\n".
*
* @throws EOFException if the stream is exhausted before the next newline
* character.
*/
public static String readAsciiLine(InputStream in) throws IOException {
// TODO: support UTF-8 here instead
StringBuilder result = new StringBuilder(80);
while (true) {
int c = in.read();
if (c == -1) {
throw new EOFException();
} else if (c == '\n') {
break;
}
result.append((char) c);
}
int length = result.length();
if (length > 0 && result.charAt(length - 1) == '\r') {
result.setLength(length - 1);
}
return result.toString();
}
示例10: skipLines
import java.io.EOFException; //导入依赖的package包/类
/**
* Skip forward the number of line delimiters. If you are in the middle of a line,
* a value of 1 will skip to the start of the next record.
* @param lines Number of lines to skip.
* @throws IOException
*/
public final void skipLines(int lines) throws IOException {
if (lines < 1) {
return;
}
long expectedLineCount = this.lineCount + lines;
try {
do {
nextChar();
} while (lineCount < expectedLineCount /*&& bufferPtr < READ_CHARS_LIMIT*/);
if (lineCount < lines) {
throw new IllegalArgumentException("Unable to skip " + lines + " lines from line " + (expectedLineCount - lines) + ". End of input reached");
}
} catch (EOFException ex) {
throw new IllegalArgumentException("Unable to skip " + lines + " lines from line " + (expectedLineCount - lines) + ". End of input reached");
}
}
示例11: getNextData
import java.io.EOFException; //导入依赖的package包/类
public MotionData getNextData() {
MotionData data = null;
try {
data = motionInputStream.readData(motionData);
return data;
} catch (EOFException e) {
try {
Thread.currentThread();
Thread.sleep(200);
} catch (InterruptedException ignore) {
}
rewind();
} catch (IOException io) {
// io.printStackTrace();
rewind();
return chip.getEmptyMotionData();
} catch (NullPointerException np) {
np.printStackTrace();
rewind();
}
return data;
}
示例12: getBytes
import java.io.EOFException; //导入依赖的package包/类
private byte[] getBytes(ZipEntry ze) throws IOException {
try (InputStream is = super.getInputStream(ze)) {
int len = (int)ze.getSize();
int bytesRead;
byte[] b;
// trust specified entry sizes when reasonably small
if (len != -1 && len <= 65535) {
b = new byte[len];
bytesRead = is.readNBytes(b, 0, len);
} else {
b = is.readAllBytes();
bytesRead = b.length;
}
if (len != -1 && len != bytesRead) {
throw new EOFException("Expected:" + len + ", read:" + bytesRead);
}
return b;
}
}
示例13: decodeAll
import java.io.EOFException; //导入依赖的package包/类
/**
* Decodes an array of instructions. The result has non-null
* elements at each offset that represents the start of an
* instruction.
*/
public static DecodedInstruction[] decodeAll(short[] encodedInstructions) {
int size = encodedInstructions.length;
DecodedInstruction[] decoded = new DecodedInstruction[size];
ShortArrayCodeInput in = new ShortArrayCodeInput(encodedInstructions);
try {
while (in.hasMore()) {
decoded[in.cursor()] = DecodedInstruction.decode(in);
}
} catch (EOFException ex) {
throw new DexException(ex);
}
return decoded;
}
示例14: read
import java.io.EOFException; //导入依赖的package包/类
public int read(byte[] b, int off, int len) throws EOFException {
if (link.isEmpty()) {
return 0;
}
int olen = len;
while (true) {
ByteBuffer bb = link.getFirst();
if (len < bb.remaining()) {
bb.get(b, off, len);
incrReadByteCount(len);
return olen;
}
int rem = bb.remaining();
bb.get(b, off, rem);
incrReadByteCount(rem);
len -= rem;
off += rem;
if (!removeFirstLink(bb)) {
break;
}
}
return olen - len;
}
示例15: getLiteralSchema
import java.io.EOFException; //导入依赖的package包/类
private static CompleteType getLiteralSchema(QueryContext context, byte[] bytes) {
try(
BufferAllocator allocator = context.getAllocator().newChildAllocator("convert-from-json-sampling", 0, 1024*1024);
BufferManager bufferManager = new BufferManagerImpl(allocator);
ArrowBuf data = allocator.buffer(bytes.length);
VectorContainer container = new VectorContainer(allocator);
VectorAccessibleComplexWriter vc = new VectorAccessibleComplexWriter(container)
){
data.writeBytes(bytes);
JsonReader jsonReader = new JsonReader(bufferManager.getManagedBuffer(), false, false, false);
jsonReader.setSource(bytes);
ComplexWriter writer = new ComplexWriterImpl("dummy", vc);
writer.setPosition(0);
ReadState state = jsonReader.write(writer);
if(state == ReadState.END_OF_STREAM){
throw new EOFException("Unexpected arrival at end of JSON literal stream");
}
container.buildSchema();
return CompleteType.fromField(container.getSchema().getFields().get(0));
}catch(Exception ex){
throw UserException.validationError(ex).message("Failure while trying to parse JSON literal.").build(logger);
}
}