/** * Encode a String value * * @param buffer The PDU in which the value will be put * @param string The String to be encoded. It is supposed to be UTF-8 * @throws EncoderException if the PDU in which the value should be encoded is * two small */ public static void encode( ByteBuffer buffer, String string ) throws EncoderException { if ( buffer == null ) { throw new EncoderException( I18n.err( I18n.ERR_00003_CANNOT_PUT_PDU_IN_NULL_BUFFER ) ); } try { buffer.put( UniversalTag.OCTET_STRING.getValue() ); byte[] value = Asn1StringUtils.getBytesUtf8( string ); buffer.put( TLV.getBytes( value.length ) ); if ( value.length != 0 ) { buffer.put( value ); } } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_00004_PDU_BUFFER_SIZE_TOO_SMALL ), boe ); } }
/** * Encode a BIT STRING value * * @param buffer The PDU in which the value will be put * @param bitString The BitString to be encoded. * @throws EncoderException if the PDU in which the value should be encoded is * two small */ public static void encode( ByteBuffer buffer, BitString bitString ) throws EncoderException { if ( buffer == null ) { throw new EncoderException( I18n.err( I18n.ERR_00003_CANNOT_PUT_PDU_IN_NULL_BUFFER ) ); } try { buffer.put( UniversalTag.BIT_STRING.getValue() ); // The BitString length. We add one byte for the unused number // of bits byte[] bytes = bitString.getData(); int length = bytes.length; buffer.put( TLV.getBytes( length ) ); buffer.put( bytes ); } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_00004_PDU_BUFFER_SIZE_TOO_SMALL ), boe ); } }
/** * Encode an OID value * * @param buffer The PDU in which the value will be put * @param oid The OID to be encoded * @throws EncoderException if the PDU in which the value should be encoded is * two small */ public static void encode( ByteBuffer buffer, Oid oid ) throws EncoderException { if ( buffer == null ) { throw new EncoderException( I18n.err( I18n.ERR_00003_CANNOT_PUT_PDU_IN_NULL_BUFFER ) ); } try { buffer.put( UniversalTag.OCTET_STRING.getValue() ); buffer.put( TLV.getBytes( oid.getEncodedLength() ) ); if ( oid.getEncodedLength() != 0 ) { oid.writeBytesTo( buffer ); } } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_00004_PDU_BUFFER_SIZE_TOO_SMALL ), boe ); } }
/** * Encode an integer value * * @param buffer The PDU in which the value will be put * @param value The integer to be encoded * @throws EncoderException if the PDU in which the value should be encoded is * two small */ public static void encode( ByteBuffer buffer, int value ) throws EncoderException { if ( buffer == null ) { throw new EncoderException( I18n.err( I18n.ERR_00003_CANNOT_PUT_PDU_IN_NULL_BUFFER ) ); } try { buffer.put( UniversalTag.INTEGER.getValue() ); buffer.put( ( byte ) getNbBytes( value ) ); buffer.put( getBytes( value ) ); } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_00004_PDU_BUFFER_SIZE_TOO_SMALL ), boe ); } }
/** * Encode a long value * * @param buffer The PDU in which the value will be put * @param value The long to be encoded * @throws EncoderException if the PDU in which the value should be encoded is * two small */ public static void encode( ByteBuffer buffer, long value ) throws EncoderException { if ( buffer == null ) { throw new EncoderException( I18n.err( I18n.ERR_00003_CANNOT_PUT_PDU_IN_NULL_BUFFER ) ); } try { buffer.put( UniversalTag.INTEGER.getValue() ); buffer.put( ( byte ) getNbBytes( value ) ); buffer.put( getBytes( value ) ); } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_00004_PDU_BUFFER_SIZE_TOO_SMALL ), boe ); } }
/** * Encode an integer value * * @param buffer The PDU in which the value will be put * @param tag The tag if it's not an UNIVERSAL one * @param value The integer to be encoded * @throws EncoderException if the PDU in which the value should be encoded is * two small */ public static void encode( ByteBuffer buffer, byte tag, int value ) throws EncoderException { if ( buffer == null ) { throw new EncoderException( I18n.err( I18n.ERR_00003_CANNOT_PUT_PDU_IN_NULL_BUFFER ) ); } try { buffer.put( tag ); buffer.put( ( byte ) getNbBytes( value ) ); buffer.put( getBytes( value ) ); } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_00004_PDU_BUFFER_SIZE_TOO_SMALL ), boe ); } }
/** * Encode an enumerated value * * @param buffer The PDU in which the value will be put * @param value The integer to be encoded * @throws EncoderException if the PDU in which the value should be encoded is * two small */ public static void encodeEnumerated( ByteBuffer buffer, int value ) throws EncoderException { if ( buffer == null ) { throw new EncoderException( I18n.err( I18n.ERR_00003_CANNOT_PUT_PDU_IN_NULL_BUFFER ) ); } try { buffer.put( UniversalTag.ENUMERATED.getValue() ); buffer.put( TLV.getBytes( getNbBytes( value ) ) ); buffer.put( getBytes( value ) ); } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_00004_PDU_BUFFER_SIZE_TOO_SMALL ), boe ); } }
/** * Encode a boolean value * * @param buffer The PDU in which the value will be put * @param bool The boolean to be encoded * @throws EncoderException if the PDU in which the value should be encoded is * two small */ public static void encode( ByteBuffer buffer, boolean bool ) throws EncoderException { if ( buffer == null ) { throw new EncoderException( I18n.err( I18n.ERR_00003_CANNOT_PUT_PDU_IN_NULL_BUFFER ) ); } try { if ( bool ) { buffer.put( ENCODED_TRUE ); } else { buffer.put( ENCODED_FALSE ); } } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_00004_PDU_BUFFER_SIZE_TOO_SMALL ), boe ); } }
/** * Encode the AddResponse message to a PDU. * * @param buffer The buffer where to put the PDU * @return The encoded response * @throws EncoderException If teh encoding failed */ @Override public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException { try { // The AddResponse Tag buffer.put( LdapCodecConstants.ADD_RESPONSE_TAG ); buffer.put( TLV.getBytes( addResponseLength ) ); // The LdapResult ( ( LdapResultDecorator ) getLdapResult() ).encode( buffer ); return buffer; } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_04005 ), boe ); } }
/** * Encode the Unbind protocolOp part */ @Override public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException { try { // The tag buffer.put( LdapCodecConstants.UNBIND_REQUEST_TAG ); // The length is always null. buffer.put( ( byte ) 0 ); } catch ( BufferOverflowException boe ) { String msg = I18n.err( I18n.ERR_04005 ); throw new EncoderException( msg, boe ); } return buffer; }
/** * Encode the DelRequest message to a PDU. * <br> * DelRequest : * <pre> * 0x4A LL entry * </pre> * * @param buffer The buffer where to put the PDU */ @Override public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException { try { // The DelRequest Tag buffer.put( LdapCodecConstants.DEL_REQUEST_TAG ); // The entry buffer.put( TLV.getBytes( dnBytes.length ) ); buffer.put( dnBytes ); } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_04005 ), boe ); } return buffer; }
/** * Encode the DelResponse message to a PDU. * * @param buffer The buffer where to put the PDU */ @Override public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException { try { // The DelResponse Tag buffer.put( LdapCodecConstants.DEL_RESPONSE_TAG ); buffer.put( TLV.getBytes( deleteResponseLength ) ); // The LdapResult ( ( LdapResultDecorator ) getLdapResult() ).encode( buffer ); } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_04005 ), boe ); } return buffer; }
/** * Encode the ModifyResponse message to a PDU. * * @param buffer The buffer where to put the PDU */ @Override public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException { try { // The ModifyResponse Tag buffer.put( LdapCodecConstants.MODIFY_RESPONSE_TAG ); buffer.put( TLV.getBytes( modifyResponseLength ) ); // The LdapResult ( ( LdapResultDecorator ) getLdapResult() ).encode( buffer ); } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_04005 ), boe ); } return buffer; }
/** * Encode the Abandon protocolOp part */ @Override public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException { try { // The tag buffer.put( LdapCodecConstants.ABANDON_REQUEST_TAG ); // The length. It has to be evaluated depending on // the abandoned messageId value. buffer.put( ( byte ) BerValue.getNbBytes( getAbandoned() ) ); // The abandoned messageId buffer.put( BerValue.getBytes( getAbandoned() ) ); } catch ( BufferOverflowException boe ) { String msg = I18n.err( I18n.ERR_04005 ); throw new EncoderException( msg, boe ); } return buffer; }
/** * Encode the CompareResponse message to a PDU. * * @param buffer The buffer where to put the PDU */ @Override public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException { try { // The CompareResponse Tag buffer.put( LdapCodecConstants.COMPARE_RESPONSE_TAG ); buffer.put( TLV.getBytes( compareResponseLength ) ); // The LdapResult ( ( LdapResultDecorator ) getLdapResult() ).encode( buffer ); } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_04005 ), boe ); } return buffer; }
/** * Encode the SearchResultDone message to a PDU. * * @param buffer The buffer where to put the PDU * return The encoded response * @throws EncoderException If the encoding failed */ @Override public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException { try { // The searchResultDone Tag buffer.put( LdapCodecConstants.SEARCH_RESULT_DONE_TAG ); buffer.put( TLV.getBytes( searchResultDoneLength ) ); // The LdapResult ( ( LdapResultDecorator ) getLdapResult() ).encode( buffer ); } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_04005 ), boe ); } return buffer; }
/** * Encode the ModifyDnResponse message to a PDU. * * @param buffer The buffer where to put the PDU */ @Override public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException { try { // The ModifyResponse Tag buffer.put( LdapCodecConstants.MODIFY_DN_RESPONSE_TAG ); buffer.put( TLV.getBytes( modifyDnResponseLength ) ); // The LdapResult ( ( LdapResultDecorator ) getLdapResult() ).encode( buffer ); } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_04005 ), boe ); } return buffer; }
/** * Encode the OrFilter message to a PDU. * <br> * OrFilter : * <pre> * 0xA1 LL filter.encode() * </pre> * * @param buffer The buffer where to put the PDU * @return The PDU. */ @Override public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException { if ( buffer == null ) { throw new EncoderException( I18n.err( I18n.ERR_04023 ) ); } try { // The OrFilter Tag buffer.put( ( byte ) LdapCodecConstants.OR_FILTER_TAG ); buffer.put( TLV.getBytes( filtersLength ) ); } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_04005 ), boe ); } super.encode( buffer ); return buffer; }
/** * Encode the PresentFilter message to a PDU. PresentFilter : 0x87 LL * attributeDescription * * @param buffer The buffer where to put the PDU * @return The PDU. */ @Override public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException { if ( buffer == null ) { throw new EncoderException( I18n.err( I18n.ERR_04023 ) ); } try { // The PresentFilter Tag buffer.put( ( byte ) LdapCodecConstants.PRESENT_FILTER_TAG ); buffer.put( TLV.getBytes( attributeDescriptionBytes.length ) ); buffer.put( attributeDescriptionBytes ); } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_04005 ), boe ); } return buffer; }
/** * Encode the AndFilter message to a PDU. * <br> * AndFilter : * <pre> * 0xA0 LL * filter.encode() ... filter.encode() * </pre> * * @param buffer The buffer where to put the PDU * @return The PDU. */ @Override public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException { if ( buffer == null ) { throw new EncoderException( I18n.err( I18n.ERR_04023 ) ); } try { // The AndFilter Tag buffer.put( ( byte ) LdapCodecConstants.AND_FILTER_TAG ); buffer.put( TLV.getBytes( filtersLength ) ); } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_04005 ), boe ); } super.encode( buffer ); return buffer; }
/** * Encode the NotFilter message to a PDU. * <br> * NotFilter : * <pre> * 0xA2 LL filter.encode() * </pre> * * @param buffer The buffer where to put the PDU * @return The PDU. */ @Override public ByteBuffer encode( ByteBuffer buffer ) throws EncoderException { if ( buffer == null ) { throw new EncoderException( I18n.err( I18n.ERR_04023 ) ); } try { // The NotFilter Tag buffer.put( ( byte ) LdapCodecConstants.NOT_FILTER_TAG ); buffer.put( TLV.getBytes( filtersLength ) ); } catch ( BufferOverflowException boe ) { throw new EncoderException( I18n.err( I18n.ERR_04005 ), boe ); } super.encode( buffer ); return buffer; }
/** * Returns a long value out of a byte array. * * @param byteArray The byte array to be converted into its decimal representation * @return The long value representing the byte array */ public static long toLongFromByteArray(byte[] byteArray) { // Allocating a byte buffer holding 8 bytes for the long value ByteBuffer bb = ByteBuffer.allocate(8); // In case the provided byte array is smaller than 8 bytes (e.g. int has 4 bytes), take care that they are placed at the right-most position if (byteArray.length < 8) { bb.position(8-byteArray.length); bb.put(byteArray); } else { try { bb.put(byteArray); } catch (BufferOverflowException e) { getLogger().warn("Byte array length is too big (" + byteArray.length + " bytes) to be converted " + "into a long value. Only the right-most 8 bytes (least significant bytes " + "according to Big Endian) are used.", e); bb.position(0); bb.put(byteArray, byteArray.length - 8, byteArray.length); } } // Setting the current position to 0, otherwise getLong() would throw a BufferUnderflowException bb.position(0); return bb.getLong(); }
@Override public void handleMessage(Message msg) { try { if (msg.what == LOG_INIT) { if (mLogFile != null) throw new RuntimeException("mLogFile not null"); readLogCache((File) msg.obj); openLogFile((File) msg.obj); } else if (msg.what == LOG_MESSAGE && msg.obj instanceof LogItem) { // Ignore log messages if not yet initialized if (mLogFile == null) return; writeLogItemToDisk((LogItem) msg.obj); } else if (msg.what == TRIM_LOG_FILE) { trimLogFile(); for (LogItem li : VpnStatus.getlogbuffer()) writeLogItemToDisk(li); } else if (msg.what == FLUSH_TO_DISK) { flushToDisk(); } } catch (IOException | BufferOverflowException e) { e.printStackTrace(); VpnStatus.logError("Error during log cache: " + msg.what); VpnStatus.logException(e); } }
public static int a(ByteBuffer byteBuffer, h hVar) { try { return byteBuffer.getInt(); } catch (BufferUnderflowException e) { a(e.fillInStackTrace(), hVar, byteBuffer); if (hVar != null) { hVar.g = 10000; } return -1; } catch (BufferOverflowException e2) { a(e2.fillInStackTrace(), hVar, byteBuffer); if (hVar != null) { hVar.g = 10000; } return -1; } catch (Exception e3) { a(e3.fillInStackTrace(), hVar, byteBuffer); if (hVar != null) { hVar.g = 10000; } return -1; } }
public static ByteBuffer a(ByteBuffer byteBuffer, byte[] bArr, h hVar) { try { return byteBuffer.get(bArr); } catch (BufferUnderflowException e) { a(e.fillInStackTrace(), hVar, byteBuffer); if (hVar != null) { hVar.g = 10000; } return null; } catch (BufferOverflowException e2) { a(e2.fillInStackTrace(), hVar, byteBuffer); if (hVar != null) { hVar.g = 10000; } return null; } catch (Exception e3) { a(e3.fillInStackTrace(), hVar, byteBuffer); if (hVar != null) { hVar.g = 10000; } return null; } }
public static short b(ByteBuffer byteBuffer, h hVar) { try { return byteBuffer.getShort(); } catch (BufferUnderflowException e) { a(e.fillInStackTrace(), hVar, byteBuffer); if (hVar != null) { hVar.g = 10000; } return (short) -1; } catch (BufferOverflowException e2) { a(e2.fillInStackTrace(), hVar, byteBuffer); if (hVar != null) { hVar.g = 10000; } return (short) -1; } catch (Exception e3) { a(e3.fillInStackTrace(), hVar, byteBuffer); if (hVar != null) { hVar.g = 10000; } return (short) -1; } }
public static Byte c(ByteBuffer byteBuffer, h hVar) { try { return Byte.valueOf(byteBuffer.get()); } catch (BufferUnderflowException e) { a(e.fillInStackTrace(), hVar, byteBuffer); if (hVar != null) { hVar.g = 10000; } return null; } catch (BufferOverflowException e2) { a(e2.fillInStackTrace(), hVar, byteBuffer); if (hVar != null) { hVar.g = 10000; } return null; } catch (Exception e3) { a(e3.fillInStackTrace(), hVar, byteBuffer); if (hVar != null) { hVar.g = 10000; } return null; } }
public static long d(ByteBuffer byteBuffer, h hVar) { try { return byteBuffer.getLong(); } catch (BufferUnderflowException e) { a(e.fillInStackTrace(), hVar, byteBuffer); if (hVar != null) { hVar.g = 10000; } return 0; } catch (BufferOverflowException e2) { a(e2.fillInStackTrace(), hVar, byteBuffer); if (hVar != null) { hVar.g = 10000; } return 0; } catch (Exception e3) { a(e3.fillInStackTrace(), hVar, byteBuffer); if (hVar != null) { hVar.g = 10000; } return 0; } }
/** * Try to transfer date from InAppBB to ChannelLineBuffers.inputBuffer * If inputBuffer don't have enough free space inAppBB will have * *Return bytes cleared. * * @return */ private int clearInAppBB() { inAppBB.flip(); //ready for output int tmpSize =0; if (inAppBB.hasRemaining()){ ByteBuffer inputBuffer = lineBuffers.getInputBuffer(); //inAppBB.remaining() - 0 to limit for output, //inputBuffer.remaining() - post to limit(capasity) for input tmpSize = inAppBB.remaining() < inputBuffer.remaining() ? inAppBB.remaining() : inputBuffer.remaining(); //the lesser of two byte[] tmp = new byte[tmpSize]; try{ inAppBB.get(tmp);//may left something inputBuffer.put(tmp); }catch(BufferOverflowException|BufferUnderflowException ex){ Log.get().log(Level.SEVERE, ex.getLocalizedMessage(), ex); conn.close(); } inAppBB.compact(); //ready for in again }else inAppBB.clear(); return tmpSize; }
@Override public int encode(short[] input, int inputSize) throws NativeAudioException { if (mBufferedFrames >= mFramesPerPacket) { throw new BufferOverflowException(); } if (inputSize != mFrameSize) { throw new IllegalArgumentException("This Opus encoder implementation requires a " + "constant frame size."); } mTerminated = false; System.arraycopy(input, 0, mAudioBuffer, mFrameSize * mBufferedFrames, mFrameSize); mBufferedFrames++; if (mBufferedFrames == mFramesPerPacket) { return encode(); } return 0; }
public void receive(ByteBuffer bb, String channelId) { if (getRunningState() == RunningState.STARTED) { receiving = true; synchronized (buffer) { try { if (buffer.remaining() < bb.remaining()) log.error("The TCP/IP outbound transport is unable to keep up with the incoming data rate, dropping " + bb.remaining() + " bytes."); else buffer.put(bb); } catch (BufferOverflowException ex) { log.error("The TCP/IP outbound transport is unable to keep up with the incoming data rate, dropping " + bb.remaining() + " bytes."); } } wakupThread(); } }
private void checkSizeAndGrow(int extra) { long capacityNeeded = buf.position() + (long) extra; if (capacityNeeded > buf.limit()) { // guarantee it's possible to fit if (capacityNeeded > MAX_ARRAY_SIZE) { throw new BufferOverflowException(); } // double until hit the cap long nextCapacity = Math.min(buf.capacity() * 2L, MAX_ARRAY_SIZE); // but make sure there is enough if twice the existing capacity is still too small nextCapacity = Math.max(nextCapacity, capacityNeeded); ByteBuffer newBuf = allocate((int) nextCapacity, buf.isDirect()); buf.flip(); newBuf.put(buf); buf = newBuf; } }
public static void writeString( String s, ChannelBuffer buffer ) throws IOException { if (s == null) { // Write that it's 0. buffer.put((byte)0); return; } byte[] stringBytes = s.getBytes("UTF-8"); int bufferLength = stringBytes.length; try { if (bufferLength <= Byte.MAX_VALUE) { buffer.put((byte)1); buffer.put((byte)bufferLength); } else if (bufferLength <= Short.MAX_VALUE) { buffer.put((byte)2); buffer.putShort((short)bufferLength); } else { buffer.put((byte)3); buffer.putInt(bufferLength); } buffer.put(stringBytes); } catch (BufferOverflowException e) { e.printStackTrace(); } }
@Override public synchronized int read(long pos, ByteBuffer buf) throws IOException { if (pos > Integer.MAX_VALUE) { return 0; } else if (pos < 0) { addError("Attempted to read from a location that was less " + "than 0 at " + pos); return 0; } int i = 0, nread = 0, ipos; for (ipos = (int)pos; ipos < contents.length; ipos++) { try { buf.put(contents[ipos]); } catch (BufferOverflowException bos) { break; } nread++; totalRead++; } if ((nread == 0) && (ipos >= contents.length)) { return -1; } return nread; }
/** * Read data from our channel. * * This is called when data is known to be available, and we don't yet * have a full packet in the buffer. If the buffer is at capacity, * expand it. */ void read() throws IOException { int count; if (mReadBuffer.position() == mReadBuffer.capacity()) { if (mReadBuffer.capacity() * 2 > MAX_BUF_SIZE) { throw new BufferOverflowException(); } Log.d("ddms", "Expanding read buffer to " + mReadBuffer.capacity() * 2); ByteBuffer newBuffer = ByteBuffer.allocate(mReadBuffer.capacity() * 2); mReadBuffer.position(0); newBuffer.put(mReadBuffer); // leaves "position" at end mReadBuffer = newBuffer; } count = mChannel.read(mReadBuffer); Log.v("ddms", "Read " + count + " bytes from " + this); if (count < 0) throw new IOException("read failed"); }
/** Ensures the buffer contains enough data to read {@code length} bytes. */ private boolean ensureLoaded(ExtractorInput extractorInput, int length) throws InterruptedException, IOException { if (length + readPosition - markPosition > capacity) { throw new BufferOverflowException(); } int bytesToLoad = length - (writePosition - readPosition); if (bytesToLoad > 0) { if (!extractorInput.readFully(buffer.data, writePosition, bytesToLoad, true)) { return false; } writePosition += bytesToLoad; } return true; }
/** * Add a first empty chunk. This will throw an exception. */ @Test public void testFirstSingleChunk() { final Unchunker unchunker = new Unchunker(); final LoggingUnchunker logger = new LoggingUnchunker(unchunker); unchunker.add(ByteBuffer.wrap(new byte[] { MORE, 0,0,0,0, 0,0,0,0 })); unchunker.add(ByteBuffer.wrap(new byte[] { MORE, 0,0,0,0, 0,0,0,1, 1,2 })); try { unchunker.add(ByteBuffer.wrap(new byte[] { END, 0,0,0,0, 0,0,0,2, 3 })); Assert.fail("No BufferOverflowException thrown"); } catch (BufferOverflowException e) { // expected } assertEquals(0, logger.messages.size()); }
public void addKey(DHTKey dhtKey) { try { ++totalKeys; keyByteBuffer.putLong(dhtKey.getMSL()); keyByteBuffer.putLong(dhtKey.getLSL()); } catch (BufferOverflowException bfe) { ByteBuffer newKeyByteBuffer; Log.fine("ProtoKeyedMessageGroup keyByteBuffer overflow. Expanding."); newKeyByteBuffer = allocateKeyBuffer(currentBufferKeys() + keyBufferExpansionKeys, keyBufferAdditionalBytesPerKey); keyByteBuffer.flip(); newKeyByteBuffer.put(keyByteBuffer); keyByteBuffer = newKeyByteBuffer; keyByteBuffer.putLong(dhtKey.getMSL()); keyByteBuffer.putLong(dhtKey.getLSL()); } }
@Test public void testDelegateUndeclaredExceptionPropagation() throws Exception { // Just need some undeclared runtime exception, so BufferOverflowException it is doThrow(new BufferOverflowException()).when(_delegate).doIt(); TestInterface service = _serviceFactory.create(_remoteEndPoint); try { service.doIt(); } catch (BufferOverflowException e) { // ok } assertEquals(_metricRegistry.getMeters().get("bv.emodb.web.partition-forwarding.TestInterface.errors").getCount(), 0); verify(_delegateServiceFactory).create(_remoteEndPoint); verify(_delegate).doIt(); }