java.nio.BufferUnderflowException Java Examples

The following examples show how to use java.nio.BufferUnderflowException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ByteBufferIndexInput.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public final void readBytes(byte[] b, int offset, int len) throws IOException {
  try {
    guard.getBytes(curBuf, b, offset, len);
  } catch (BufferUnderflowException e) {
    int curAvail = curBuf.remaining();
    while (len > curAvail) {
      guard.getBytes(curBuf, b, offset, curAvail);
      len -= curAvail;
      offset += curAvail;
      curBufIndex++;
      if (curBufIndex >= buffers.length) {
        throw new EOFException("read past EOF: " + this);
      }
      setCurBuf(buffers[curBufIndex]);
      curBuf.position(0);
      curAvail = curBuf.remaining();
    }
    guard.getBytes(curBuf, b, offset, len);
  } catch (NullPointerException npe) {
    throw new AlreadyClosedException("Already closed: " + this);
  }
}
 
Example #2
Source File: ReplayCacheTestProc.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static int csize(int p) throws Exception {
    try (SeekableByteChannel chan = Files.newByteChannel(
            Paths.get(dfl(p)), StandardOpenOption.READ)) {
        chan.position(6);
        int cc = 0;
        while (true) {
            try {
                if (AuthTime.readFrom(chan) != null) cc++;
            } catch (BufferUnderflowException e) {
                break;
            }
        }
        return cc;
    } catch (IOException ioe) {
        return 0;
    }
}
 
Example #3
Source File: CompositeReadableBufferTest.java    From qpid-proton-j with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetByteWithOneArrayWithManyElements() {
    CompositeReadableBuffer buffer = new CompositeReadableBuffer();

    buffer.append(new byte[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 });

    assertEquals(10, buffer.remaining());
    assertTrue(buffer.hasRemaining());
    assertEquals(0, buffer.position());

    for (int i = 0; i < 10; ++i) {
        assertEquals(i, buffer.get());
        assertEquals(i + 1, buffer.position());
    }

    assertEquals(0, buffer.remaining());
    assertEquals(10, buffer.position());

    try {
        buffer.get();
        fail("Should not be able to read past end");
    } catch (BufferUnderflowException e) {}
}
 
Example #4
Source File: CELT11Encoder.java    From Jumble with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void getEncodedData(PacketBuffer packetBuffer) throws BufferUnderflowException {
    if (mBufferedFrames < mFramesPerPacket) {
        throw new BufferUnderflowException();
    }

    for (int x = 0; x < mBufferedFrames; x++) {
        byte[] frame = mBuffer[x];
        int head = frame.length;
        if(x < mBufferedFrames - 1)
            head |= 0x80;
        packetBuffer.append(head);
        packetBuffer.append(frame, frame.length);
    }

    mBufferedFrames = 0;
}
 
Example #5
Source File: Type1Font.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void verifyPFB(ByteBuffer bb) throws FontFormatException {

        int pos = 0;
        while (true) {
            try {
                int segType = bb.getShort(pos) & 0xffff;
                if (segType == 0x8001 || segType == 0x8002) {
                    bb.order(ByteOrder.LITTLE_ENDIAN);
                    int segLen = bb.getInt(pos+2);
                    bb.order(ByteOrder.BIG_ENDIAN);
                    if (segLen <= 0) {
                        throw new FontFormatException("bad segment length");
                    }
                    pos += segLen+6;
                } else if (segType == 0x8003) {
                    return;
                } else {
                    throw new FontFormatException("bad pfb file");
                }
            } catch (BufferUnderflowException bue) {
                throw new FontFormatException(bue.toString());
            } catch (Exception e) {
                throw new FontFormatException(e.toString());
            }
        }
    }
 
Example #6
Source File: ByteBufferResourceInput.java    From fastText4j with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public final void readBytes(byte[] b, int offset, int len) throws IOException {
  try {
    curBuf.get(b, offset, len);
  } catch (BufferUnderflowException e) {
    int curAvail = curBuf.remaining();
    while (len > curAvail) {
      curBuf.get(b, offset, curAvail);
      len -= curAvail;
      offset += curAvail;
      curBufIndex++;
      if (curBufIndex >= buffers.length) {
        throw new EOFException("read past EOF: " + this);
      }
      curBuf = buffers[curBufIndex];
      curBuf.position(0);
      curAvail = curBuf.remaining();
    }
    curBuf.get(b, offset, len);
  } catch (NullPointerException npe) {
    throw new AlreadyClosedException("Already closed: " + this);
  }
}
 
Example #7
Source File: DflCache.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private static void expunge(Path p, KerberosTime currTime)
        throws IOException {
    Path p2 = Files.createTempFile(p.getParent(), "rcache", null);
    try (SeekableByteChannel oldChan = Files.newByteChannel(p);
            SeekableByteChannel newChan = createNoClose(p2)) {
        long timeLimit = currTime.getSeconds() - readHeader(oldChan);
        while (true) {
            try {
                AuthTime at = AuthTime.readFrom(oldChan);
                if (at.ctime > timeLimit) {
                    ByteBuffer bb = ByteBuffer.wrap(at.encode(true));
                    newChan.write(bb);
                }
            } catch (BufferUnderflowException e) {
                break;
            }
        }
    }
    makeMine(p2);
    Files.move(p2, p,
            StandardCopyOption.REPLACE_EXISTING,
            StandardCopyOption.ATOMIC_MOVE);
}
 
Example #8
Source File: Type1Font.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private void verifyPFB(ByteBuffer bb) throws FontFormatException {

        int pos = 0;
        while (true) {
            try {
                int segType = bb.getShort(pos) & 0xffff;
                if (segType == 0x8001 || segType == 0x8002) {
                    bb.order(ByteOrder.LITTLE_ENDIAN);
                    int segLen = bb.getInt(pos+2);
                    bb.order(ByteOrder.BIG_ENDIAN);
                    if (segLen <= 0) {
                        throw new FontFormatException("bad segment length");
                    }
                    pos += segLen+6;
                } else if (segType == 0x8003) {
                    return;
                } else {
                    throw new FontFormatException("bad pfb file");
                }
            } catch (BufferUnderflowException bue) {
                throw new FontFormatException(bue.toString());
            } catch (Exception e) {
                throw new FontFormatException(e.toString());
            }
        }
    }
 
Example #9
Source File: Draft_76.java    From RipplePower with Apache License 2.0 6 votes vote down vote up
@Override
public Handshakedata translateHandshake( ByteBuffer buf ) throws InvalidHandshakeException {

	HandshakeBuilder bui = translateHandshakeHttp( buf, role );
	// the first drafts are lacking a protocol number which makes them difficult to distinguish. Sec-WebSocket-Key1 is typical for draft76
	if( ( bui.hasFieldValue( "Sec-WebSocket-Key1" ) || role == Role.CLIENT ) && !bui.hasFieldValue( "Sec-WebSocket-Version" ) ) {
		byte[] key3 = new byte[ role == Role.SERVER ? 8 : 16 ];
		try {
			buf.get( key3 );
		} catch ( BufferUnderflowException e ) {
			throw new IncompleteHandshakeException( buf.capacity() + 16 );
		}
		bui.setContent( key3 );

	}
	return bui;
}
 
Example #10
Source File: TypeAnnotationParser.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private static TypeAnnotation parseTypeAnnotation(ByteBuffer buf,
        ConstantPool cp,
        AnnotatedElement baseDecl,
        Class<?> container) {
    try {
        TypeAnnotationTargetInfo ti = parseTargetInfo(buf);
        LocationInfo locationInfo = LocationInfo.parseLocationInfo(buf);
        Annotation a = AnnotationParser.parseAnnotation(buf, cp, container, false);
        if (ti == null) // Inside a method for example
            return null;
        return new TypeAnnotation(ti, locationInfo, a, baseDecl);
    } catch (IllegalArgumentException | // Bad type in const pool at specified index
            BufferUnderflowException e) {
        throw new AnnotationFormatError(e);
    }
}
 
Example #11
Source File: DnsPacketTest.java    From Intra with Apache License 2.0 6 votes vote down vote up
@Test
public void testInfiniteLoop() {
  // Regression test for stack overflow in name compression.
  byte[] data = {
      -107, -6,    // [0-1]   query ID
      -127, -128,  // [2-3]   flags: RD=1, QR=1, RA=1
      0, 1,        // [4-5]   QDCOUNT (number of queries) = 1
      0, 0,        // [6-7]   ANCOUNT (number of answers) = 2
      0, 0,        // [8-9]   NSCOUNT (number of authoritative answers) = 0
      0, 0,        // [10-11] ARCOUNT (number of additional records) = 0
      // First query, encoded as an infinite loop (example.example.ex....)
      7, 'e', 'x', 'a', 'm', 'p', 'l', 'e',
      -64, 12,
      0,  // null terminator of FQDN (DNS root)
      0, 1,  // QTYPE = A
      0, 1  // QCLASS = IN (Internet)
  };

  try {
    new DnsPacket(data);
    fail("Expected parsing to fail");
  } catch (ProtocolException p) {
    assertTrue(p.getCause() instanceof BufferUnderflowException);
  }
}
 
Example #12
Source File: ReplayCacheTestProc.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static int csize(int p) throws Exception {
    try (SeekableByteChannel chan = Files.newByteChannel(
            Paths.get(dfl(p)), StandardOpenOption.READ)) {
        chan.position(6);
        int cc = 0;
        while (true) {
            try {
                if (AuthTime.readFrom(chan) != null) cc++;
            } catch (BufferUnderflowException e) {
                break;
            }
        }
        return cc;
    } catch (IOException ioe) {
        return 0;
    }
}
 
Example #13
Source File: TypeAnnotationParser.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private static TypeAnnotation parseTypeAnnotation(ByteBuffer buf,
        ConstantPool cp,
        AnnotatedElement baseDecl,
        Class<?> container) {
    try {
        TypeAnnotationTargetInfo ti = parseTargetInfo(buf);
        LocationInfo locationInfo = LocationInfo.parseLocationInfo(buf);
        Annotation a = AnnotationParser.parseAnnotation(buf, cp, container, false);
        if (ti == null) // Inside a method for example
            return null;
        return new TypeAnnotation(ti, locationInfo, a, baseDecl);
    } catch (IllegalArgumentException | // Bad type in const pool at specified index
            BufferUnderflowException e) {
        throw new AnnotationFormatError(e);
    }
}
 
Example #14
Source File: NetworkProtocol.java    From buffer_bci with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Decodes a series of events from the ByteBuffer. Handles event values and
 * types as bytes.
 *
 * @param buffer
 * @return
 * @throws ClientException
 */
public static Event[] decodeEvents(final ByteBuffer buffer)
		throws ClientException {
	final ArrayList<Event> events = new ArrayList<Event>();
	int nEvents = 0;

	// Read events while bytes remain in the buffer.
	try {
		while (buffer.position() < buffer.capacity()) {
			events.add(decodeEvent(buffer));
			nEvents++;
		}
	} catch (final BufferUnderflowException e) {
		throw new ClientException("Malformed event message");
	}

	return events.toArray(new Event[nEvents]);
}
 
Example #15
Source File: PostHandshakeContext.java    From openjsse with GNU General Public License v2.0 6 votes vote down vote up
@Override
void dispatch(byte handshakeType, ByteBuffer fragment) throws IOException {
    SSLConsumer consumer = handshakeConsumers.get(handshakeType);
    if (consumer == null) {
        throw conContext.fatal(Alert.UNEXPECTED_MESSAGE,
                "Unexpected post-handshake message: " +
                        SSLHandshake.nameOf(handshakeType));
    }

    try {
        consumer.consume(this, fragment);
    } catch (UnsupportedOperationException unsoe) {
        throw conContext.fatal(Alert.UNEXPECTED_MESSAGE,
                "Unsupported post-handshake message: " +
                        SSLHandshake.nameOf(handshakeType), unsoe);
    } catch (BufferUnderflowException | BufferOverflowException be) {
        throw conContext.fatal(Alert.DECODE_ERROR,
                "Illegal handshake message: " +
                SSLHandshake.nameOf(handshakeType), be);
    }
}
 
Example #16
Source File: AbstractBuffer.java    From catalyst with Apache License 2.0 6 votes vote down vote up
/**
 * Checks bounds for a slice.
 */
protected long checkSlice(long offset, long length) {
  checkOffset(offset);
  if (limit == -1) {
    if (offset + length > capacity) {
      if (capacity < maxCapacity) {
        capacity(calculateCapacity(offset + length));
      } else {
        throw new BufferUnderflowException();
      }
    }
  } else {
    if (offset + length > limit)
      throw new BufferUnderflowException();
  }
  return offset(offset);
}
 
Example #17
Source File: GifDecoder.java    From PLDroidShortVideo with Apache License 2.0 6 votes vote down vote up
/**
 * Reads color table as 256 RGB integer values
 *
 * @param ncolors int number of colors to read
 * @return int array containing 256 colors (packed ARGB with full alpha)
 */
protected int[] readColorTable(int ncolors) {
    int nbytes = 3 * ncolors;
    int[] tab = null;
    byte[] c = new byte[nbytes];

    try {
        rawData.get(c);

        tab = new int[256]; // max size to avoid bounds checks
        int i = 0;
        int j = 0;
        while (i < ncolors) {
            int r = ((int) c[j++]) & 0xff;
            int g = ((int) c[j++]) & 0xff;
            int b = ((int) c[j++]) & 0xff;
            tab[i++] = 0xff000000 | (r << 16) | (g << 8) | b;
        }
    } catch (BufferUnderflowException e) {
        Log.w(TAG, "Format Error Reading Color Table", e);
        status = STATUS_FORMAT_ERROR;
    }

    return tab;
}
 
Example #18
Source File: DflCache.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static void expunge(Path p, KerberosTime currTime)
        throws IOException {
    Path p2 = Files.createTempFile(p.getParent(), "rcache", null);
    try (SeekableByteChannel oldChan = Files.newByteChannel(p);
            SeekableByteChannel newChan = createNoClose(p2)) {
        long timeLimit = currTime.getSeconds() - readHeader(oldChan);
        while (true) {
            try {
                AuthTime at = AuthTime.readFrom(oldChan);
                if (at.ctime > timeLimit) {
                    ByteBuffer bb = ByteBuffer.wrap(at.encode(true));
                    newChan.write(bb);
                }
            } catch (BufferUnderflowException e) {
                break;
            }
        }
    }
    makeMine(p2);
    Files.move(p2, p,
            StandardCopyOption.REPLACE_EXISTING,
            StandardCopyOption.ATOMIC_MOVE);
}
 
Example #19
Source File: Type1Font.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private void verifyPFB(ByteBuffer bb) throws FontFormatException {

        int pos = 0;
        while (true) {
            try {
                int segType = bb.getShort(pos) & 0xffff;
                if (segType == 0x8001 || segType == 0x8002) {
                    bb.order(ByteOrder.LITTLE_ENDIAN);
                    int segLen = bb.getInt(pos+2);
                    bb.order(ByteOrder.BIG_ENDIAN);
                    if (segLen <= 0) {
                        throw new FontFormatException("bad segment length");
                    }
                    pos += segLen+6;
                } else if (segType == 0x8003) {
                    return;
                } else {
                    throw new FontFormatException("bad pfb file");
                }
            } catch (BufferUnderflowException bue) {
                throw new FontFormatException(bue.toString());
            } catch (Exception e) {
                throw new FontFormatException(e.toString());
            }
        }
    }
 
Example #20
Source File: MqttMessage.java    From xenqtt with Apache License 2.0 6 votes vote down vote up
private static byte[] getBytes(int index, int len, ByteBuffer buffer) {

		if (index < 0 || index > buffer.limit()) {
			throw new IndexOutOfBoundsException();
		}

		if (len < 0) {
			throw new IllegalArgumentException("len must be >= 0");
		}

		if (len > buffer.limit() - index) {
			throw new BufferUnderflowException();
		}

		byte[] buf = new byte[len];
		if (len > 0) {
			System.arraycopy(buffer.array(), index, buf, 0, len);
		}

		return buf;
	}
 
Example #21
Source File: Type1Font.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private void verifyPFB(ByteBuffer bb) throws FontFormatException {

        int pos = 0;
        while (true) {
            try {
                int segType = bb.getShort(pos) & 0xffff;
                if (segType == 0x8001 || segType == 0x8002) {
                    bb.order(ByteOrder.LITTLE_ENDIAN);
                    int segLen = bb.getInt(pos+2);
                    bb.order(ByteOrder.BIG_ENDIAN);
                    if (segLen <= 0) {
                        throw new FontFormatException("bad segment length");
                    }
                    pos += segLen+6;
                } else if (segType == 0x8003) {
                    return;
                } else {
                    throw new FontFormatException("bad pfb file");
                }
            } catch (BufferUnderflowException bue) {
                throw new FontFormatException(bue.toString());
            } catch (Exception e) {
                throw new FontFormatException(e.toString());
            }
        }
    }
 
Example #22
Source File: Type1Font.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
private int nextTokenType(ByteBuffer bb) {

        try {
            byte b = skip(bb);

            while (true) {
                if (b == (byte)'/') { // PS defined name follows.
                    return PSNAMETOKEN;
                } else if (b == (byte)'(') { // PS string follows
                    return PSSTRINGTOKEN;
                } else if ((b == (byte)'\r') || (b == (byte)'\n')) {
                b = skip(bb);
                } else {
                    b = bb.get();
                }
            }
        } catch (BufferUnderflowException e) {
            return PSEOFTOKEN;
        }
    }
 
Example #23
Source File: ConstantPoolParser.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/** Parse the constant pool of the class
 *  calling a method visit* each time a constant pool entry is parsed.
 *
 *  The order of the calls to visit* is not guaranteed to be the same
 *  than the order of the constant pool entry in the bytecode array.
 *
 * @param visitor
 * @throws InvalidConstantPoolFormatException
 */
public void parse(ConstantPoolVisitor visitor) throws InvalidConstantPoolFormatException {
    ByteBuffer buffer = ByteBuffer.wrap(classFile);
    buffer.position(getStartOffset()); //skip header

    Object[] values = new Object[getLength()];
    try {
        parseConstantPool(buffer, values, visitor);
    } catch(BufferUnderflowException e) {
        throw new InvalidConstantPoolFormatException(e);
    }
    if (endOffset == 0) {
        endOffset = buffer.position();
        secondHeader = new char[4];
        for (int i = 0; i < secondHeader.length; i++) {
            secondHeader[i] = (char) getUnsignedShort(buffer);
        }
    }
    resolveConstantPool(values, visitor);
}
 
Example #24
Source File: DflCache.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static void expunge(Path p, KerberosTime currTime)
        throws IOException {
    Path p2 = Files.createTempFile(p.getParent(), "rcache", null);
    try (SeekableByteChannel oldChan = Files.newByteChannel(p);
            SeekableByteChannel newChan = createNoClose(p2)) {
        long timeLimit = currTime.getSeconds() - readHeader(oldChan);
        while (true) {
            try {
                AuthTime at = AuthTime.readFrom(oldChan);
                if (at.ctime > timeLimit) {
                    ByteBuffer bb = ByteBuffer.wrap(at.encode(true));
                    newChan.write(bb);
                }
            } catch (BufferUnderflowException e) {
                break;
            }
        }
    }
    makeMine(p2);
    Files.move(p2, p,
            StandardCopyOption.REPLACE_EXISTING,
            StandardCopyOption.ATOMIC_MOVE);
}
 
Example #25
Source File: TarsInputStream.java    From TarsJava with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public boolean skipToTag(int tag) {
    try {
        HeadData hd = new HeadData();
        while (true) {
            int len = peakHead(hd);
            if (hd.type == TarsStructBase.STRUCT_END) {
                return false;
            }
            if (tag <= hd.tag) return tag == hd.tag;
            skip(len);
            skipField(hd.type);
        }
    } catch (TarsDecodeException | BufferUnderflowException e) {
    }
    return false;
}
 
Example #26
Source File: DflCache.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static void expunge(Path p, KerberosTime currTime)
        throws IOException {
    Path p2 = Files.createTempFile(p.getParent(), "rcache", null);
    try (SeekableByteChannel oldChan = Files.newByteChannel(p);
            SeekableByteChannel newChan = createNoClose(p2)) {
        long timeLimit = currTime.getSeconds() - readHeader(oldChan);
        while (true) {
            try {
                AuthTime at = AuthTime.readFrom(oldChan);
                if (at.ctime > timeLimit) {
                    ByteBuffer bb = ByteBuffer.wrap(at.encode(true));
                    newChan.write(bb);
                }
            } catch (BufferUnderflowException e) {
                break;
            }
        }
    }
    makeMine(p2);
    Files.move(p2, p,
            StandardCopyOption.REPLACE_EXISTING,
            StandardCopyOption.ATOMIC_MOVE);
}
 
Example #27
Source File: ReplayCacheTestProc.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private static int csize(int p) throws Exception {
    try (SeekableByteChannel chan = Files.newByteChannel(
            Paths.get(dfl(p)), StandardOpenOption.READ)) {
        chan.position(6);
        int cc = 0;
        while (true) {
            try {
                if (AuthTime.readFrom(chan) != null) cc++;
            } catch (BufferUnderflowException e) {
                break;
            }
        }
        return cc;
    } catch (IOException ioe) {
        return 0;
    }
}
 
Example #28
Source File: Type1Font.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
private void verifyPFB(ByteBuffer bb) throws FontFormatException {

        int pos = 0;
        while (true) {
            try {
                int segType = bb.getShort(pos) & 0xffff;
                if (segType == 0x8001 || segType == 0x8002) {
                    bb.order(ByteOrder.LITTLE_ENDIAN);
                    int segLen = bb.getInt(pos+2);
                    bb.order(ByteOrder.BIG_ENDIAN);
                    if (segLen <= 0) {
                        throw new FontFormatException("bad segment length");
                    }
                    pos += segLen+6;
                } else if (segType == 0x8003) {
                    return;
                } else {
                    throw new FontFormatException("bad pfb file");
                }
            } catch (BufferUnderflowException bue) {
                throw new FontFormatException(bue.toString());
            } catch (Exception e) {
                throw new FontFormatException(e.toString());
            }
        }
    }
 
Example #29
Source File: TypeAnnotationParser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
private static TypeAnnotation parseTypeAnnotation(ByteBuffer buf,
        ConstantPool cp,
        AnnotatedElement baseDecl,
        Class<?> container) {
    try {
        TypeAnnotationTargetInfo ti = parseTargetInfo(buf);
        LocationInfo locationInfo = LocationInfo.parseLocationInfo(buf);
        Annotation a = AnnotationParser.parseAnnotation(buf, cp, container, false);
        if (ti == null) // Inside a method for example
            return null;
        return new TypeAnnotation(ti, locationInfo, a, baseDecl);
    } catch (IllegalArgumentException | // Bad type in const pool at specified index
            BufferUnderflowException e) {
        throw new AnnotationFormatError(e);
    }
}
 
Example #30
Source File: RecordFromBinaryFileCreator.java    From kieker with Apache License 2.0 6 votes vote down vote up
private void processBuffer(final ReaderRegistry<String> registry, final IValueDeserializer deserializer,
		final OutputPort<IMonitoringRecord> outputPort) throws IOException {
	this.buffer.flip();

	try {
		/** Needs at least an record id. */
		while ((this.buffer.position() + 4) <= this.buffer.limit()) {
			this.buffer.mark();
			final IMonitoringRecord record = this.deserializeRecord(registry, deserializer);
			if (record == null) {
				return;
			} else {
				outputPort.send(record);
			}
		}
		this.buffer.mark();
		this.buffer.compact();
	} catch (final BufferUnderflowException ex) {
		RecordFromBinaryFileCreator.LOGGER.warn("Unexpected buffer underflow. Resetting and compacting buffer.", ex);
		this.buffer.reset();
		this.buffer.compact();
		throw ex;
	}
}