Java 类java.io.EOFException 实例源码

项目:flume-release-1.7.0    文件:LogFile.java   
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;
}
项目:QDrill    文件:TextInput.java   
/**
 * 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");
  }
}
项目:android-source-codes    文件:DiskLruCache.java   
/**
 * 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();
}
项目:openjdk-jdk10    文件:BinaryParser.java   
@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;
}
项目:hadoop-oss    文件:TestCryptoStreams.java   
@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);
}
项目:incubator-netbeans    文件:NIOStreams.java   
@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");
        }
    }
}
项目:s-store    文件:ScriptReaderBinary.java   
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;
        }
    }
项目:JkImageLoader    文件:DiskLruCache.java   
/**
 * 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();
}
项目:Renrentou    文件:DiskLruCache.java   
/**
 * 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();
}
项目:dremio-oss    文件:TextInput.java   
/**
 * 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");
  }
}
项目:jaer    文件:MotionViewer.java   
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;
        }
项目:openjdk-jdk10    文件:JarFile.java   
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;
    }
}
项目:javaide    文件:DecodedInstruction.java   
/**
 * 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;
}
项目:jsf-sdk    文件:LinkedBufferInput.java   
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;
}
项目:simple-share-android    文件:Streams.java   
/**
 * 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();
}
项目:dremio-oss    文件:ConvertFromJsonConverter.java   
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);
  }
}
项目:hadoop-oss    文件:Client.java   
/** Check the rpc response header. */
void checkResponse(RpcResponseHeaderProto header) throws IOException {
  if (header == null) {
    throw new EOFException("Response is null.");
  }
  if (header.hasClientId()) {
    // check client IDs
    final byte[] id = header.getClientId().toByteArray();
    if (!Arrays.equals(id, RpcConstants.DUMMY_CLIENT_ID)) {
      if (!Arrays.equals(id, clientId)) {
        throw new IOException("Client IDs not matched: local ID="
            + StringUtils.byteToHexString(clientId) + ", ID in response="
            + StringUtils.byteToHexString(header.getClientId().toByteArray()));
      }
    }
  }
}
项目:s-store    文件:HsqlByteArrayInputStream.java   
public final void readFully(byte[] b, int off,
                            int len) throws IOException {

    if (len < 0) {
        throw new IndexOutOfBoundsException();
    }

    int n = 0;

    while (n < len) {
        int count = read(b, off + n, len - n);

        if (count < 0) {
            throw new EOFException();
        }

        n += count;
    }
}
项目:Hubs    文件:IoLib.java   
public static LuaValue freaduntil(File f,boolean lineonly) throws IOException {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    int c;
    try {
        if ( lineonly ) {
            loop: while ( (c = f.read()) > 0 ) { 
                switch ( c ) {
                case '\r': break;
                case '\n': break loop;
                default: baos.write(c); break;
                }
            }
        } else {
            while ( (c = f.read()) > 0 ) 
                baos.write(c);
        }
    } catch ( EOFException e ) {
        c = -1;
    }
    return ( c < 0 && baos.size() == 0 )? 
        (LuaValue) NIL:
        (LuaValue) LuaString.valueUsing(baos.toByteArray());
}
项目:OpenJSharp    文件:ZipFile.java   
int readLeUnsignedShort() throws IOException
{
  int result;
  if(pos + 1 < buffer.length)
    {
      result = ((buffer[pos + 0] & 0xff) | (buffer[pos + 1] & 0xff) << 8);
      pos += 2;
    }
  else
    {
      int b0 = read();
      int b1 = read();
      if (b1 == -1)
        throw new EOFException();
      result = (b0 & 0xff) | (b1 & 0xff) << 8;
    }
  return result;
}
项目:parabuild-ci    文件:HsqlByteArrayInputStream.java   
public final void readFully(byte[] b, int off,
                            int len) throws IOException {

    if (len < 0) {
        throw new IndexOutOfBoundsException();
    }

    int n = 0;

    while (n < len) {
        int count = read(b, off + n, len - n);

        if (count < 0) {
            throw new EOFException();
        }

        n += count;
    }
}
项目:geomapapp    文件:ParseLink.java   
static String parseComment(BufferedReader in) throws IOException {
    StringBuffer sb = new StringBuffer();
    boolean white = false;
    int count = 0;
    while( true ) {
        int i = in.read();
        if( i==-1 )throw new EOFException();
        char c = (char)i;
        if( Character.isWhitespace(c) ) {
            if( white )continue;
            white = true;
            sb.append(' ');
            continue;
        }
        if( c=='<' )count++;
        if( c=='>' ) {
            if( count==0) {
            //  System.out.println("comment:\t"+sb.toString());
                return sb.toString();
            }
            count--;
        }
        sb.append(c);
        white = false;
    }
}
项目:tomcat7    文件:UpgradeNioProcessor.java   
private int fillReadBuffer(boolean block) throws IOException {
    int nRead;
    if (block) {
        Selector selector = null;
        try {
            selector = pool.get();
        } catch ( IOException x ) {
            // Ignore
        }
        try {
            NioEndpoint.KeyAttachment att =
                    (NioEndpoint.KeyAttachment) nioChannel.getAttachment();
            if (att == null) {
                throw new IOException("Key must be cancelled.");
            }
            nRead = pool.read(nioChannel.getBufHandler().getReadBuffer(),
                    nioChannel, selector, att.getTimeout());
        } catch (EOFException eof) {
            nRead = -1;
        } finally {
            if (selector != null) {
                pool.put(selector);
            }
        }
    } else {
        nRead = nioChannel.read(nioChannel.getBufHandler().getReadBuffer());
    }
    return nRead;
}
项目:openjdk-jdk10    文件:RIFFReader.java   
public long readLong() throws IOException {
    long ch1 = read();
    long ch2 = read();
    long ch3 = read();
    long ch4 = read();
    long ch5 = read();
    long ch6 = read();
    long ch7 = read();
    long ch8 = read();
    if (ch1 < 0)
        throw new EOFException();
    if (ch2 < 0)
        throw new EOFException();
    if (ch3 < 0)
        throw new EOFException();
    if (ch4 < 0)
        throw new EOFException();
    if (ch5 < 0)
        throw new EOFException();
    if (ch6 < 0)
        throw new EOFException();
    if (ch7 < 0)
        throw new EOFException();
    if (ch8 < 0)
        throw new EOFException();
    return ch1 | (ch2 << 8) | (ch3 << 16) | (ch4 << 24)
            | (ch5 << 32) | (ch6 << 40) | (ch7 << 48) | (ch8 << 56);
}
项目:PlusGram    文件:ID3v2DataInput.java   
public byte readByte() throws IOException {
    int b = input.read();
    if (b < 0) {
        throw new EOFException();
    }
    return (byte) b;
}
项目:openjdk-jdk10    文件:RIFFReader.java   
public int readInt() throws IOException {
    int ch1 = read();
    int ch2 = read();
    int ch3 = read();
    int ch4 = read();
    if (ch1 < 0)
        throw new EOFException();
    if (ch2 < 0)
        throw new EOFException();
    if (ch3 < 0)
        throw new EOFException();
    if (ch4 < 0)
        throw new EOFException();
    return ch1 + (ch2 << 8) | (ch3 << 16) | (ch4 << 24);
}
项目:ExoPlayer-Offline    文件:FakeTrackOutput.java   
@Override
public int sampleData(ExtractorInput input, int length, boolean allowEndOfInput)
    throws IOException, InterruptedException {
  byte[] newData = new byte[length];
  int bytesAppended = input.read(newData, 0, length);
  if (bytesAppended == C.RESULT_END_OF_INPUT) {
    if (allowEndOfInput) {
      return C.RESULT_END_OF_INPUT;
    }
    throw new EOFException();
  }
  newData = Arrays.copyOf(newData, bytesAppended);
  sampleData = TestUtil.joinByteArrays(sampleData, newData);
  return bytesAppended;
}
项目:dev-courses    文件:HsqlByteArrayInputStream.java   
public final int readUnsignedShort() throws IOException {

        int ch1 = read();
        int ch2 = read();

        if ((ch1 | ch2) < 0) {
            throw new EOFException();
        }

        return (ch1 << 8) + (ch2);
    }
项目:hadoop    文件:TestNodeStatusUpdater.java   
@Override
public NodeHeartbeatResponse nodeHeartbeat(NodeHeartbeatRequest request)
    throws YarnException, IOException {
  heartBeatID++;
  if(heartBeatID == 1) {
    // EOFException should be retried as well.
    throw new EOFException("NodeHeartbeat exception");
  }
  else {
  throw new java.net.ConnectException(
      "NodeHeartbeat exception");
  }
}
项目:ApkMultiChannelPlugin    文件:IntReader.java   
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();
        }
}
项目:lams    文件:ByteBufferIndexInput.java   
@Override
public int readInt(long pos) throws IOException {
  try {
    return curBuf.getInt((int) pos);
  } catch (IllegalArgumentException e) {
    if (pos < 0) {
      throw new IllegalArgumentException("Seeking to negative position: " + this, e);
    } else {
      throw new EOFException("seek past EOF: " + this);
    }
  } catch (NullPointerException npe) {
    throw new AlreadyClosedException("Already closed: " + this);
  }
}
项目:Reer    文件:DaemonStopEvent.java   
@Override
public DaemonStopEvent read(Decoder decoder) throws EOFException, Exception {
    long timestamp = decoder.readLong();
    long pid = decoder.readLong();
    DaemonExpirationStatus status = decoder.readBoolean() ? DaemonExpirationStatus.values()[decoder.readByte()] : null;
    String reason = decoder.readNullableString();
    return new DaemonStopEvent(new Date(timestamp), pid, status, reason);
}
项目:s-store    文件:ReaderDataInput.java   
public final int readUnsignedShort() throws IOException {

        int b1 = read();
        int b2 = read();

        if ((b1 | b2) < 0) {
            throw new EOFException();
        }

        return ((b1 << 8) + (b2));
    }
项目:parabuild-ci    文件:ScaledRAFile.java   
public void read(byte[] b, int offset, int length) throws IOException {

        try {
            if (bufferDirty || seekPosition < bufferOffset
                    || seekPosition >= bufferOffset + buffer.length) {
                readIntoBuffer();
            } else {
                cacheHit++;
            }

            ba.reset();

            if (seekPosition - bufferOffset
                    != ba.skip(seekPosition - bufferOffset)) {
                throw new EOFException();
            }

            int bytesRead = ba.read(b, offset, length);

            seekPosition += bytesRead;

            if (bytesRead < length) {
                if (seekPosition != realPosition) {
                    file.seek(seekPosition);
                }

                file.readFully(b, offset + bytesRead, length - bytesRead);

                seekPosition += (length - bytesRead);
                realPosition = seekPosition;
            }
        } catch (IOException e) {
            resetPointer();
            appLog.logContext(e, null);

            throw e;
        }
    }
项目:openjdk-jdk10    文件:ModuleInfo.java   
@Override
public byte readByte() throws IOException {
    try {
        return bb.get();
    } catch (BufferUnderflowException e) {
        throw new EOFException(e.getMessage());
    }
}
项目:NGB-master    文件:BlockCompressedDataInputStream.java   
/**
 * Reads an int value from stream
 * @return an int value
 * @throws IOException if no value was read
 */
public final int readInt() throws IOException {
    int ch1 = read();
    int ch2 = read();
    int ch3 = read();
    int ch4 = read();
    if ((ch1 | ch2 | ch3 | ch4) < 0) {
        throw new EOFException();
    }
    return (ch1 << SHIFT24) + (ch2 << TWO_BYTE_SIZE) + (ch3 << BYTE_SIZE) + ch4;
}
项目:RedisDirectory    文件:RedisInputStream.java   
@Override
public void seek(long pos) throws IOException {
    int newBufferIndex = (int) (pos / Constants.BUFFER_SIZE);
    if (newBufferIndex != currentBufferIndex) {
        currentBufferIndex = newBufferIndex;
        setCurrentBuffer();
    }
    bufferPosition = (int) (pos % Constants.BUFFER_SIZE);
    if (getFilePointer() > length()) {
        throw new EOFException("seek beyond EOF: pos=" + getFilePointer() + " vs length=" + length() + ": " + this);
    }
}
项目:Codeforces    文件:DiskBasedCache.java   
/**
 * Simple wrapper around {@link InputStream#read()} that throws EOFException
 * instead of returning -1.
 */
private static int read(InputStream is) throws IOException {
    int b = is.read();
    if (b == -1) {
        throw new EOFException();
    }
    return b;
}
项目:monarch    文件:DiskInitFileParser.java   
private void readEndOfRecord(DataInput di) throws IOException {
  int b = di.readByte();
  if (b != DiskInitFile.END_OF_RECORD_ID) {
    if (b == 0) {
      // this is expected if this is the last record and we died while writing it.
      throw new EOFException("found partial last record");
    } else {
      // Our implementation currently relies on all unwritten bytes having
      // a value of 0. So throw this exception if we find one we didn't expect.
      throw new IllegalStateException("expected end of record (byte=="
          + DiskInitFile.END_OF_RECORD_ID + ") or zero but found " + b);
    }
  }
}
项目:elasticsearch_my    文件:ByteArrayIndexInput.java   
@Override
public byte readByte() throws IOException {
    if (pos >= offset + length) {
        throw new EOFException("seek past EOF");
    }
    return bytes[offset + pos++];
}