当前位置: 首页>>代码示例>>Java>>正文


Java BufferUnderflowException类代码示例

本文整理汇总了Java中java.nio.BufferUnderflowException的典型用法代码示例。如果您正苦于以下问题:Java BufferUnderflowException类的具体用法?Java BufferUnderflowException怎么用?Java BufferUnderflowException使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


BufferUnderflowException类属于java.nio包,在下文中一共展示了BufferUnderflowException类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: validateForNativeProtocol

import java.nio.BufferUnderflowException; //导入依赖的package包/类
public void validateForNativeProtocol(ByteBuffer bytes, ProtocolVersion version)
{
    try
    {
        ByteBuffer input = bytes.duplicate();
        int n = readCollectionSize(input, version);
        for (int i = 0; i < n; i++)
            elements.validate(readValue(input, version));

        if (input.hasRemaining())
            throw new MarshalException("Unexpected extraneous bytes after list value");
    }
    catch (BufferUnderflowException e)
    {
        throw new MarshalException("Not enough bytes to read a list");
    }
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:18,代码来源:ListSerializer.java

示例2: getSerializedValue

import java.nio.BufferUnderflowException; //导入依赖的package包/类
/**
 * Given a serialized map, gets the value associated with a given key.
 * @param serializedMap a serialized map
 * @param serializedKey a serialized key
 * @param keyType the key type for the map
 * @return the value associated with the key if one exists, null otherwise
 */
public ByteBuffer getSerializedValue(ByteBuffer serializedMap, ByteBuffer serializedKey, AbstractType keyType)
{
    try
    {
        ByteBuffer input = serializedMap.duplicate();
        int n = readCollectionSize(input, ProtocolVersion.V3);
        for (int i = 0; i < n; i++)
        {
            ByteBuffer kbb = readValue(input, ProtocolVersion.V3);
            ByteBuffer vbb = readValue(input, ProtocolVersion.V3);
            int comparison = keyType.compare(kbb, serializedKey);
            if (comparison == 0)
                return vbb;
            else if (comparison > 0)
                // since the map is in sorted order, we know we've gone too far and the element doesn't exist
                return null;
        }
        return null;
    }
    catch (BufferUnderflowException e)
    {
        throw new MarshalException("Not enough bytes to read a map");
    }
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:32,代码来源:MapSerializer.java

示例3: validateForNativeProtocol

import java.nio.BufferUnderflowException; //导入依赖的package包/类
public void validateForNativeProtocol(ByteBuffer bytes, ProtocolVersion version)
{
    try
    {
        ByteBuffer input = bytes.duplicate();
        int n = readCollectionSize(input, version);
        for (int i = 0; i < n; i++)
            elements.validate(readValue(input, version));
        if (input.hasRemaining())
            throw new MarshalException("Unexpected extraneous bytes after set value");
    }
    catch (BufferUnderflowException e)
    {
        throw new MarshalException("Not enough bytes to read a set");
    }
}
 
开发者ID:Netflix,项目名称:sstable-adaptor,代码行数:17,代码来源:SetSerializer.java

示例4: decodeInternal

import java.nio.BufferUnderflowException; //导入依赖的package包/类
@Override
C decodeInternal(ByteBuffer input) {
  if (input == null || input.remaining() == 0) return newInstance(0);
  try {
    ByteBuffer i = input.duplicate();
    int size = readSize(i);
    C coll = newInstance(size);
    for (int pos = 0; pos < size; pos++) {
      ByteBuffer databb = readValue(i);
      coll.add(elementCodec.decode(databb));
    }
    return coll;
  } catch (BufferUnderflowException e) {
    throw new InvalidTypeException("Not enough bytes to deserialize collection", e);
  }
}
 
开发者ID:datastax,项目名称:simulacron,代码行数:17,代码来源:CqlMapper.java

示例5: readImpl

import java.nio.BufferUnderflowException; //导入依赖的package包/类
@Override
protected void readImpl()
{
	_targetX  = readD();
	_targetY  = readD();
	_targetZ  = readD();
	_originX  = readD();
	_originY  = readD();
	_originZ  = readD();
	try
	{
		_moveMovement = readD(); // is 0 if cursor keys are used  1 if mouse is used
	}
	catch (BufferUnderflowException e)
	{
		// ignore for now
           if(Config.L2WALKER_PROTECTION)   
           {   
           	L2PcInstance activeChar = getClient().getActiveChar();   
           	activeChar.sendPacket(SystemMessageId.HACKING_TOOL);   
           	Util.handleIllegalPlayerAction(activeChar, "Player " + activeChar.getName() + " Tried to Use L2Walker And Got Kicked", IllegalPlayerAction.PUNISH_KICK);   
           }   
	 }
}
 
开发者ID:L2jBrasil,项目名称:L2jBrasil,代码行数:25,代码来源:MoveBackwardToLocation.java

示例6: verifyPFB

import java.nio.BufferUnderflowException; //导入依赖的package包/类
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());
            }
        }
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:27,代码来源:Type1Font.java

示例7: send

import java.nio.BufferUnderflowException; //导入依赖的package包/类
synchronized void send(ByteBuffer b) throws IOException {
    byte[] msgBytes = new byte[b.capacity()];
    try {
    	/**
    	 * position:相当于一个游标(cursor),记录我们从哪里开始写数据,从哪里开始读数据。
    	         位置:下一个要被读或写的元素的索引,每次读写缓冲区数据时都会改变该值,为下次读写作准备
    	 */
        b.position(0);
        b.get(msgBytes);
    } catch (BufferUnderflowException be) {
        LOG.error("BufferUnderflowException ", be);
        return;
    }
    dout.writeInt(b.capacity());
    dout.write(b.array());
    dout.flush();
}
 
开发者ID:maoling,项目名称:fuck_zookeeper,代码行数:18,代码来源:QuorumCnxManager.java

示例8: translateHandshake

import java.nio.BufferUnderflowException; //导入依赖的package包/类
@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;
}
 
开发者ID:LDLN,项目名称:Responder-Android,代码行数:18,代码来源:Draft_76.java

示例9: putData

import java.nio.BufferUnderflowException; //导入依赖的package包/类
private void putData(ByteBuffer input, ByteBuffer output) {
	int id = input.getInt();
	int size = input.getInt();
	byte[] entity = new byte[size];

	try {
		input.get(entity);
	} catch (BufferUnderflowException bue) {
	}
	publish(id, entity);

	System.out.println("Bytes sent into the data server: ");
	/*ByteBuffer buf = ByteBuffer.wrap(entity);
	 while (true) {
	 try {
	 System.out.println("" + buf.get() + " " + buf.get() + " " + buf.get() + " " + buf.get());
	 } catch (BufferUnderflowException bue) {
	 break;
	 }
	 }*/
}
 
开发者ID:roscisz,项目名称:KernelHive,代码行数:22,代码来源:DataPublisher.java

示例10: byteArrayReadByteTest

import java.nio.BufferUnderflowException; //导入依赖的package包/类
@Test
public void byteArrayReadByteTest() throws IOException {
  // Mix positives and negatives to test sign preservation in readByte()
  byte[] bytes = new byte[] {-128, -127, -126, -1, 0, 1, 125, 126, 127};
  try (RandomAccessObject obj = new RandomAccessObject.RandomAccessByteArrayObject(bytes)) {
    for (int x = 0; x < bytes.length; x++) {
      Assert.assertEquals(bytes[x], obj.readByte());
    }

    try {
      obj.readByte();
      Assert.fail("Should've thrown an IOException");
    } catch (BufferUnderflowException expected) {
    }
  }
}
 
开发者ID:lizhangqu,项目名称:CorePatch,代码行数:17,代码来源:RandomAccessObjectTest.java

示例11: byteArrayReadUnsignedByteTest

import java.nio.BufferUnderflowException; //导入依赖的package包/类
@Test
public void byteArrayReadUnsignedByteTest() throws IOException {
  // Test values above 127 to test unsigned-ness of readUnsignedByte()
  int[] ints = new int[] {255, 254, 253};
  byte[] bytes = new byte[] {(byte) 0xff, (byte) 0xfe, (byte) 0xfd};
  try (RandomAccessObject obj = new RandomAccessObject.RandomAccessByteArrayObject(bytes)) {
    for (int x = 0; x < bytes.length; x++) {
      Assert.assertEquals(ints[x], obj.readUnsignedByte());
    }

    try {
      obj.readUnsignedByte();
      Assert.fail("Should've thrown an IOException");
    } catch (BufferUnderflowException expected) {
    }
  }
}
 
开发者ID:lizhangqu,项目名称:CorePatch,代码行数:18,代码来源:RandomAccessObjectTest.java

示例12: mmapReadIntTest

import java.nio.BufferUnderflowException; //导入依赖的package包/类
@Test
public void mmapReadIntTest() throws IOException {
  File tmpFile = storeInTempFile(new ByteArrayInputStream(BLOB));

  try {
    RandomAccessObject obj =
        new RandomAccessObject.RandomAccessMmapObject(new RandomAccessFile(tmpFile, "r"), "r");
    readIntTest(obj);

    try {
      obj.readInt();
      Assert.fail("Should've thrown an BufferUnderflowException");
    } catch (BufferUnderflowException expected) {
    }
  } finally {
    tmpFile.delete();
  }
}
 
开发者ID:lizhangqu,项目名称:CorePatch,代码行数:19,代码来源:RandomAccessObjectTest.java

示例13: BitcoinPacketHeader

import java.nio.BufferUnderflowException; //导入依赖的package包/类
public BitcoinPacketHeader(ByteBuffer in) throws ProtocolException, BufferUnderflowException {
    header = new byte[HEADER_LENGTH];
    in.get(header, 0, header.length);

    int cursor = 0;

    // The command is a NULL terminated string, unless the command fills all twelve bytes
    // in which case the termination is implicit.
    for (; header[cursor] != 0 && cursor < COMMAND_LEN; cursor++) ;
    byte[] commandBytes = new byte[cursor];
    System.arraycopy(header, 0, commandBytes, 0, cursor);
    command = Utils.toString(commandBytes, "US-ASCII");
    cursor = COMMAND_LEN;

    size = (int) readUint32(header, cursor);
    cursor += 4;

    if (size > Message.MAX_SIZE || size < 0)
        throw new ProtocolException("Message size too large: " + size);

    // Old clients don't send the checksum.
    checksum = new byte[4];
    // Note that the size read above includes the checksum bytes.
    System.arraycopy(header, cursor, checksum, 0, 4);
    cursor += 4;
}
 
开发者ID:creativechain,项目名称:creacoinj,代码行数:27,代码来源:BitcoinSerializer.java

示例14: a

import java.nio.BufferUnderflowException; //导入依赖的package包/类
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;
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:24,代码来源:g.java

示例15: expunge

import java.nio.BufferUnderflowException; //导入依赖的package包/类
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);
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:24,代码来源:DflCache.java


注:本文中的java.nio.BufferUnderflowException类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。