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


Java ByteArrayInputStream.skip方法代码示例

本文整理汇总了Java中java.io.ByteArrayInputStream.skip方法的典型用法代码示例。如果您正苦于以下问题:Java ByteArrayInputStream.skip方法的具体用法?Java ByteArrayInputStream.skip怎么用?Java ByteArrayInputStream.skip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.io.ByteArrayInputStream的用法示例。


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

示例1: readMarkAndReset

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
public void readMarkAndReset(byte[] bytes,int mark) {
    StringBuffer sb = new StringBuffer();
    ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
    bais.mark(mark);

    bais.skip(mark + 1);
    int tmp;
    while ((tmp = bais.read()) != -1) {
        sb.append(Integer.toHexString(tmp));
    }

    System.out.println("越过标记后的字符串");
    System.out.println(sb.toString());

    bais.reset();
    sb.setLength(0);

    int m;
    while ((m = bais.read()) != -1) {
        sb.append(Integer.toHexString(m));
    }

    System.out.println("重置之后的字符串");
    System.out.println(sb.toString());
}
 
开发者ID:byhieg,项目名称:JavaTutorial,代码行数:26,代码来源:ByteArrayInputStreamExample.java

示例2: deserialize

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
public static final Object deserialize(byte[] bytes) throws Exception {
	if (bytes == null || bytes.length < 4) {
		return new LinkedHashMap<>();
	}

	// Try to deserialize content as Object (type-safe serialization)
	if (bytes[0] == 1) {
		try {
			ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
			bais.skip(1);
			return new ObjectInputStream(bais).readObject();
		} catch (Throwable ignored) {
		}
	}

	// Read content as JSON
	bytes = Arrays.copyOfRange(bytes, 1, bytes.length);
	String json = new String(bytes, StandardCharsets.UTF_8);
	return TreeReaderRegistry.getReader(null).parse(json);
}
 
开发者ID:berkesa,项目名称:datatree,代码行数:21,代码来源:JavaBuiltin.java

示例3: generatePatchAndCheckCtrlEntries

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
/**
 * Generates a patch from the differences between |oldData| and |newData| and checks that the
 * patch's control data matches |expected|. For the sake of simplicity, assumes that chars are
 * always 1 byte.
 *
 * @param oldData
 * @param newData
 * @param expected The expected control entries in the generated patch
 * @return returns whether the actual control entries in the generated patch match the expected
 *     ones
 */
private boolean generatePatchAndCheckCtrlEntries(
    String oldData, String newData, CtrlEntry[] expected) throws Exception {
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
  byte[] oldBytes = oldData.getBytes(Charset.forName("US-ASCII"));
  byte[] newBytes = newData.getBytes(Charset.forName("US-ASCII"));
  RandomAccessObject oldBytesRo = new RandomAccessObject.RandomAccessByteArrayObject(oldBytes);
  RandomAccessObject newBytesRo = new RandomAccessObject.RandomAccessByteArrayObject(newBytes);
  BsDiffPatchWriter.generatePatchWithMatcher(
      oldBytesRo, newBytesRo, new NaiveMatcher(oldBytes, newBytes), outputStream);

  ByteArrayInputStream patchInputStream = new ByteArrayInputStream(outputStream.toByteArray());
  for (CtrlEntry element : expected) {
    if (patchInputStream.available() < 24
        || BsUtil.readFormattedLong(patchInputStream) != element.diffLength
        || BsUtil.readFormattedLong(patchInputStream) != element.extraLength
        || BsUtil.readFormattedLong(patchInputStream) != element.oldOffset) {
      return false;
    }

    patchInputStream.skip(element.diffLength + element.extraLength);
  }

  if (patchInputStream.available() > 0) {
    return false;
  }

  return true;
}
 
开发者ID:lizhangqu,项目名称:CorePatch,代码行数:40,代码来源:BsDiffTest.java

示例4: getArrayOfIntValues

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
/**
 * Returns array of int values.
 */
public int[] getArrayOfIntValues() {

    byte[] bufArray = (byte[])myValue;
    if (bufArray != null) {

        //ArrayList valList = new ArrayList();
        ByteArrayInputStream bufStream =
            new ByteArrayInputStream(bufArray);
        int available = bufStream.available();

        // total number of values is at the end of the stream
        bufStream.mark(available);
        bufStream.skip(available-1);
        int length = bufStream.read();
        bufStream.reset();

        int[] valueArray = new int[length];
        for (int i = 0; i < length; i++) {
            // read length
            int valLength = bufStream.read();
            if (valLength != 4) {
                // invalid data
                return null;
            }

            byte[] bufBytes = new byte[valLength];
            bufStream.read(bufBytes, 0, valLength);
            valueArray[i] = convertToInt(bufBytes);

        }
        return valueArray;
    }
    return null;
}
 
开发者ID:SunburstApps,项目名称:OpenJSharp,代码行数:38,代码来源:AttributeClass.java

示例5: getArrayOfStringValues

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
/**
 * Returns array of String values.
 */
public String[] getArrayOfStringValues() {

    byte[] bufArray = (byte[])myValue;
    if (bufArray != null) {
        ByteArrayInputStream bufStream =
            new ByteArrayInputStream(bufArray);
        int available = bufStream.available();

        // total number of values is at the end of the stream
        bufStream.mark(available);
        bufStream.skip(available-1);
        int length = bufStream.read();
        bufStream.reset();

        String[] valueArray = new String[length];
        for (int i = 0; i < length; i++) {
            // read length
            int valLength = bufStream.read();
            byte[] bufBytes = new byte[valLength];
            bufStream.read(bufBytes, 0, valLength);
            try {
                valueArray[i] = new String(bufBytes, "UTF-8");
            } catch (java.io.UnsupportedEncodingException uee) {
            }
        }
        return valueArray;
    }
    return null;
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:33,代码来源:AttributeClass.java

示例6: testEncodeReplyResponse

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
@Test
public void testEncodeReplyResponse() throws Exception {

    URL url = URL.valueOf( ThriftProtocol.NAME + "://127.0.0.1:40880/" + Demo.Iface.class.getName() );

    Channel channel = new MockedChannel( url );

    Request request = createRequest();

    RpcResult rpcResult = new RpcResult();
    rpcResult.setResult( "Hello, World!" );

    Response response = new Response();
    response.setResult( rpcResult );
    response.setId( request.getId() );
    ChannelBuffer bos = ChannelBuffers.dynamicBuffer(1024);

    ThriftCodec.RequestData rd = ThriftCodec.RequestData.create(
            ThriftCodec.getSeqId(), Demo.Iface.class.getName(), "echoString" );
    ThriftCodec.cachedRequest.putIfAbsent( request.getId(), rd );
    codec.encode( channel, bos, response );

    byte[] buf = new byte[bos.writerIndex() - 4];
    System.arraycopy( bos.array(), 4, buf, 0, bos.writerIndex() - 4 );

    ByteArrayInputStream bis = new ByteArrayInputStream( buf );

    if ( bis.markSupported() ) {
        bis.mark( 0 );
    }

    TIOStreamTransport transport = new TIOStreamTransport( bis );
    TBinaryProtocol protocol = new TBinaryProtocol( transport );

    Assert.assertEquals( ThriftCodec.MAGIC, protocol.readI16() );
    Assert.assertEquals( protocol.readI32() + 4, bos.writerIndex() );
    int headerLength = protocol.readI16();

    Assert.assertEquals( ThriftCodec.VERSION, protocol.readByte() );
    Assert.assertEquals( Demo.Iface.class.getName(), protocol.readString() );
    Assert.assertEquals( request.getId(), protocol.readI64() );

    if ( bis.markSupported() ) {
        bis.reset();
        bis.skip( headerLength );
    }

    TMessage message = protocol.readMessageBegin();
    Assert.assertEquals( "echoString", message.name );
    Assert.assertEquals( TMessageType.REPLY, message.type );
    Assert.assertEquals( ThriftCodec.getSeqId(), message.seqid );
    Demo.echoString_result result = new Demo.echoString_result();
    result.read( protocol );
    protocol.readMessageEnd();

    Assert.assertEquals( rpcResult.getValue(), result.getSuccess() );
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:58,代码来源:ThriftCodecTest.java

示例7: open

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
@Override
public void open(long offset) throws ProxyCacheException {
    arrayInputStream = new ByteArrayInputStream(data);
    arrayInputStream.skip(offset);
}
 
开发者ID:Achenglove,项目名称:AndroidVideoCache,代码行数:6,代码来源:ByteArraySource.java

示例8: testEncodeExceptionResponse

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
@Test
public void testEncodeExceptionResponse() throws Exception {

    URL url = URL.valueOf( ThriftProtocol.NAME + "://127.0.0.1:40880/" + Demo.Iface.class.getName() );

    Channel channel = new MockedChannel( url );

    Request request = createRequest();

    RpcResult rpcResult = new RpcResult();
    String exceptionMessage = "failed";
    rpcResult.setException( new RuntimeException( exceptionMessage ) );

    Response response = new Response();
    response.setResult( rpcResult );
    response.setId( request.getId() );
    ChannelBuffer bos = ChannelBuffers.dynamicBuffer(1024);

    ThriftCodec.RequestData rd = ThriftCodec.RequestData.create(
            ThriftCodec.getSeqId(), Demo.Iface.class.getName(), "echoString" );
    ThriftCodec.cachedRequest.put( request.getId(), rd );
    codec.encode( channel, bos, response );

    byte[] buf = new byte[bos.writerIndex() - 4];
    System.arraycopy( bos.array(), 4, buf, 0, bos.writerIndex() - 4 );
    ByteArrayInputStream bis = new ByteArrayInputStream( buf);

    if ( bis.markSupported() ) {
        bis.mark( 0 );
    }

    TIOStreamTransport transport = new TIOStreamTransport( bis );
    TBinaryProtocol protocol = new TBinaryProtocol( transport );

    Assert.assertEquals( ThriftCodec.MAGIC, protocol.readI16() );
    Assert.assertEquals( protocol.readI32() + 4, bos.writerIndex() );
    int headerLength = protocol.readI16();

    Assert.assertEquals( ThriftCodec.VERSION, protocol.readByte() );
    Assert.assertEquals( Demo.Iface.class.getName(), protocol.readString() );
    Assert.assertEquals( request.getId(), protocol.readI64() );

    if ( bis.markSupported() ) {
        bis.reset();
        bis.skip( headerLength );
    }

    TMessage message = protocol.readMessageBegin();
    Assert.assertEquals( "echoString", message.name );
    Assert.assertEquals( TMessageType.EXCEPTION, message.type );
    Assert.assertEquals( ThriftCodec.getSeqId(), message.seqid );
    TApplicationException exception = TApplicationException.read( protocol );
    protocol.readMessageEnd();

    Assert.assertEquals( exceptionMessage, exception.getMessage() );

}
 
开发者ID:zhuxiaolei,项目名称:dubbo2,代码行数:58,代码来源:ThriftCodecTest.java

示例9: readFrom

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
public static Configuration readFrom(ByteArrayInputStream bis) {
    int len = bis.read();

    int rfAddress = Parser.readRfAddress(bis);
    DeviceType type = DeviceType.fromId(bis.read());

    byte[] unknown = new byte[3];
    bis.read(unknown, 0, unknown.length);

    byte[] serialBytes = new byte[10];
    bis.read(serialBytes, 0, serialBytes.length);
    String serial = new String(serialBytes, UTF_8);

    if (type == DeviceType.THERMOSTAST_PLUS || type == DeviceType.THERMOSTAST) {
        double temperatureComfort = bis.read() / 2.0;
        double temperatureEco = bis.read() / 2.0;
        double temperatureSetpointMax = bis.read() / 2.0;
        double temperatureSetpointMin = bis.read() / 2.0;
        double temperatureOffset = bis.read() / 2.0 - 3.5;
        double temperatureWindowOpen = bis.read() / 2.0;
        int durationWindowOpen = bis.read();
        int durationBoost = bis.read();
        int decalcification = bis.read();
        double valveMaximum = bis.read() * 100/255.0;
        double valveOffset = bis.read() * 100/255.0;

        // TODO decipher the weekly program, always has a length of 182
        bis.skip(bis.available());

        return new ValveConfiguration(type, rfAddress, serial,
                temperatureComfort, temperatureEco, temperatureSetpointMax, temperatureSetpointMin, temperatureOffset,
                temperatureWindowOpen, durationWindowOpen, durationBoost, decalcification, valveMaximum, valveOffset);
    } else if (type == DeviceType.CUBE) {
        // TODO decipher the cube configuration
        bis.skip(bis.available());
    }

    if (bis.available() > 0) {
        String message = String.format(Locale.ROOT, "Device of type [%s] claims a length of [%s] and has [%s] unread bytes", type,
                len, bis.available());
        throw new IllegalStateException(message);
    }

    return new Configuration(type, rfAddress, serial);
}
 
开发者ID:spinscale,项目名称:maxcube-java,代码行数:46,代码来源:Configuration.java

示例10: seek

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
private void seek(ByteArrayInputStream is, long pos){
    is.reset();
    is.skip(pos);
}
 
开发者ID:Ptrk25,项目名称:CDN-FX-2.2,代码行数:5,代码来源:IconImgInfoReceiver.java

示例11: testEncodeRequest

import java.io.ByteArrayInputStream; //导入方法依赖的package包/类
@Test
public void testEncodeRequest() throws Exception {

    Request request = createRequest();

    ChannelBuffer output = ChannelBuffers.dynamicBuffer(1024);

    codec.encode( channel, output, request );

    byte[] bytes = new byte[output.readableBytes()];
    output.readBytes(bytes);

    ByteArrayInputStream bis = new ByteArrayInputStream( bytes );

    TTransport transport = new TIOStreamTransport( bis );

    TBinaryProtocol protocol = new TBinaryProtocol( transport );

    // frame
    byte[] length = new byte[4];
    transport.read( length, 0, 4 );

    if ( bis.markSupported() ) {
        bis.mark( 0 );
    }

    // magic
    Assert.assertEquals( ThriftCodec.MAGIC, protocol.readI16() );

    // message length
    int messageLength = protocol.readI32();
    Assert.assertEquals( messageLength + 4, bytes.length );

    // header length
    short headerLength = protocol.readI16();
    // version
    Assert.assertEquals( ThriftCodec.VERSION, protocol.readByte() );
    // service name
    Assert.assertEquals( Demo.Iface.class.getName(), protocol.readString() );
    // dubbo request id
    Assert.assertEquals( request.getId(), protocol.readI64() );

    // test message header length
    if ( bis.markSupported() ) {
        bis.reset();
        bis.skip( headerLength );
    }

    TMessage message = protocol.readMessageBegin();

    Demo.echoString_args args = new Demo.echoString_args();

    args.read( protocol );

    protocol.readMessageEnd();

    Assert.assertEquals( "echoString", message.name );

    Assert.assertEquals( TMessageType.CALL, message.type );

    Assert.assertEquals( "Hello, World!", args.getArg() );

}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:64,代码来源:ThriftCodecTest.java


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