java.io.EOFException类的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(5.5k)|赞(0)|评价(0)|浏览(565)

本文整理了Java中java.io.EOFException类的一些代码示例,展示了EOFException类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EOFException类的具体详情如下:
包路径:java.io.EOFException
类名称:EOFException

EOFException介绍

[英]Thrown when a program encounters the end of a file or stream during an input operation.
[中]当程序在输入操作期间遇到文件或流的结尾时引发。

代码示例

代码示例来源:origin: libgdx/libgdx

public void readFully (byte[] b, int off, int len) throws IOException {
  while (len > 0) {
    int count = is.read(b, off, len);
    if (count <= 0) {
      throw new EOFException();
    }
    off += count;
    len -= count;
  }
}

代码示例来源:origin: commons-io/commons-io

/**
 * Handle End of File.
 *
 * @return <code>-1</code> if <code>throwEofException</code> is
 * set to {@code false}
 * @throws EOFException if <code>throwEofException</code> is set
 * to {@code true}.
 */
private int doEndOfFile() throws EOFException {
  eof = true;
  if (throwEofException) {
    throw new EOFException();
  }
  return EOF;
}

代码示例来源:origin: libgdx/libgdx

private void skipFully (int count) throws IOException {
  while (count > 0) {
    long skipped = in.skip(count);
    if (skipped <= 0) throw new EOFException("Unable to skip.");
    count -= skipped;
  }
}

代码示例来源:origin: square/okio

@Test public void eofExceptionProvidesLimitedContent() throws IOException {
 data.writeUtf8("aaaaaaaabbbbbbbbccccccccdddddddde");
 try {
  source.readUtf8LineStrict();
  fail();
 } catch (EOFException expected) {
  assertEquals("\\n not found: limit=33 content=616161616161616162626262626262626363636363636363"
    + "6464646464646464…", expected.getMessage());
 }
}

代码示例来源:origin: apache/flink

@Override
public int readUnsignedByte() throws IOException {
  if (this.position < this.end) {
    return (this.buffer[this.position++] & 0xff);
  } else {
    throw new EOFException();
  }
}

代码示例来源:origin: libgdx/libgdx

private void skipFully (int count) throws IOException {
  while (count > 0) {
    long skipped = in.skip(count);
    if (skipped <= 0) throw new EOFException("Unable to skip.");
    count -= skipped;
  }
}

代码示例来源:origin: square/okio

@Test public void readUtf8LineStrictNoBytesConsumedOnFailure() throws IOException {
 data.writeUtf8("abc\n");
 try {
  source.readUtf8LineStrict(2);
  fail();
 } catch (EOFException expected) {
  assertTrue(expected.getMessage().startsWith("\\n not found: limit=2 content=61626"));
 }
 assertEquals("abc", source.readUtf8LineStrict(3));
}

代码示例来源:origin: google/guava

/**
  * Reads a byte from the input stream checking that the end of file (EOF) has not been
  * encountered.
  *
  * @return byte read from input
  * @throws IOException if an error is encountered while reading
  * @throws EOFException if the end of file (EOF) is encountered.
  */
 private byte readAndCheckByte() throws IOException, EOFException {
  int b1 = in.read();

  if (-1 == b1) {
   throw new EOFException();
  }

  return (byte) b1;
 }
}

代码示例来源:origin: apache/flink

@Override
public void skipBytesToWrite(int numBytes) throws IOException {
  if (buffer.length - this.position < numBytes){
    throw new EOFException("Could not skip " + numBytes + " bytes.");
  }
  this.position += numBytes;
}

代码示例来源:origin: libgdx/libgdx

private void skipFully (int count) throws IOException {
  while (count > 0) {
    long skipped = in.skip(count);
    if (skipped <= 0) throw new EOFException("Unable to skip.");
    count -= skipped;
  }
}

代码示例来源:origin: square/okio

@Test public void readLines() throws IOException {
 data.writeUtf8("abc\ndef\n");
 assertEquals("abc", source.readUtf8LineStrict());
 assertEquals("def", source.readUtf8LineStrict());
 try {
  source.readUtf8LineStrict();
  fail();
 } catch (EOFException expected) {
  assertEquals("\\n not found: limit=0 content=…", expected.getMessage());
 }
}

代码示例来源:origin: libgdx/libgdx

public void readFully (byte[] b, int off, int len) throws IOException {
  while (len > 0) {
    int count = is.read(b, off, len);
    if (count <= 0) {
      throw new EOFException();
    }
    off += count;
    len -= count;
  }
}

代码示例来源:origin: apache/flink

@Override
public char readChar() throws IOException {
  if (this.position < this.end - 1) {
    return (char) (((this.memory[this.position++] & 0xff) << 8) | ((this.memory[this.position++] & 0xff) << 0));
  } else {
    throw new EOFException();
  }
}

代码示例来源:origin: libgdx/libgdx

private void skipFully (int count) throws IOException {
  while (count > 0) {
    long skipped = in.skip(count);
    if (skipped <= 0) throw new EOFException("Unable to skip.");
    count -= skipped;
  }
}

代码示例来源:origin: prestodb/presto

private int read() throws IOException {
  int v = is.read();
  if (v != -1) {
    readBytes++;
    return v;
  } else {
    throw new EOFException();
  }
}

代码示例来源:origin: apache/flink

@Override
public short readShort() throws IOException {
  if (position >= 0 && position < this.end - 1) {
    return (short) ((((this.memory[position++]) & 0xff) << 8) | (((this.memory[position++]) & 0xff) << 0));
  } else {
    throw new EOFException();
  }
}

代码示例来源:origin: apache/flink

@Override
public void seek(long desired) throws IOException {
  if (desired < this.pos) {
    throw new IllegalArgumentException("Wrapped InputStream: cannot search backwards.");
  }
  while (this.pos < desired) {
    long numReadBytes = this.inStream.skip(desired - pos);
    if (numReadBytes == -1) {
      throw new EOFException("Unexpected EOF during forward seek.");
    }
    this.pos += numReadBytes;
  }
}

代码示例来源:origin: commons-io/commons-io

/**
   * Reads the next byte from the input stream.
   * @param input  the stream
   * @return the byte
   * @throws IOException if the end of file is reached
   */
  private static int read(final InputStream input)
    throws IOException
  {
    final int value = input.read();

    if( EOF == value ) {
      throw new EOFException( "Unexpected EOF reached" );
    }

    return value;
  }
}

代码示例来源:origin: apache/flink

@Override
public boolean readBoolean() throws IOException {
  if (this.position < this.end) {
    return this.buffer[this.position++] != 0;
  } else {
    throw new EOFException();
  }
}

代码示例来源:origin: square/spoon

public final void skip(int bytes) throws IOException {
  if (bytes<=0) {
    return;
  }
  long skipped=m_stream.skip(bytes);
  m_position+=skipped;
  if (skipped!=bytes) {
    throw new EOFException();
  }
}

相关文章