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


Java JBBPBitInputStream类代码示例

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


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

示例1: testReadWrite

import com.igormaznitsa.jbbp.io.JBBPBitInputStream; //导入依赖的package包/类
@Test
public void testReadWrite() throws Exception {
    final VarCustomImpl impl = new VarCustomImpl();

    final byte[] etalonArray = new byte[319044];
    RND.nextBytes(etalonArray);
    etalonArray[0] = 1;

    impl.read(new JBBPBitInputStream(new ByteArrayInputStream(etalonArray)));

    assertEquals(1, impl.getBYTEA());

    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    final JBBPBitOutputStream bios = new JBBPBitOutputStream(bos);

    impl.write(bios);
    bios.close();

    assertArrayEquals(etalonArray, bos.toByteArray());
}
 
开发者ID:raydac,项目名称:java-binary-block-parser,代码行数:21,代码来源:VarCustomTest.java

示例2: parse

import com.igormaznitsa.jbbp.io.JBBPBitInputStream; //导入依赖的package包/类
/**
 * Parse am input stream with defined external value provider.
 *
 * @param in                    an input stream which content will be parsed, it must not be null
 * @param varFieldProcessor     a var field processor, it may be null if there is
 *                              not any var field in a script, otherwise NPE will be thrown during parsing
 * @param externalValueProvider an external value provider, it can be null but
 *                              only if the script doesn't have fields desired the provider
 * @return the parsed content as the root structure
 * @throws IOException it will be thrown for transport errors
 */
public JBBPFieldStruct parse(final InputStream in, final JBBPVarFieldProcessor varFieldProcessor, final JBBPExternalValueProvider externalValueProvider) throws IOException {
    final JBBPBitInputStream bitInStream = in instanceof JBBPBitInputStream ? (JBBPBitInputStream) in : new JBBPBitInputStream(in, bitOrder);
    this.finalStreamByteCounter = bitInStream.getCounter();

    final JBBPNamedNumericFieldMap fieldMap;
    if (this.compiledBlock.hasEvaluatedSizeArrays() || this.compiledBlock.hasVarFields()) {
        fieldMap = new JBBPNamedNumericFieldMap(externalValueProvider);
    } else {
        fieldMap = null;
    }

    if (this.compiledBlock.hasVarFields()) {
        JBBPUtils.assertNotNull(varFieldProcessor, "The Script contains VAR fields, a var field processor must be provided");
    }
    try {
        return new JBBPFieldStruct(new JBBPNamedFieldInfo("", "", -1), parseStruct(bitInStream, new JBBPIntCounter(), varFieldProcessor, fieldMap, new JBBPIntCounter(), new JBBPIntCounter(), false));
    } finally {
        this.finalStreamByteCounter = bitInStream.getCounter();
    }
}
 
开发者ID:raydac,项目名称:java-binary-block-parser,代码行数:32,代码来源:JBBPParser.java

示例3: readValueFromPackedDecimal

import com.igormaznitsa.jbbp.io.JBBPBitInputStream; //导入依赖的package包/类
public static long readValueFromPackedDecimal(final JBBPBitInputStream in, final int len, final boolean signed) throws IOException {
    final byte[] data = in.readByteArray(len);

    StringBuilder digitStr = new StringBuilder();
    for (int i = 0; i < len * 2; i++) {
        byte currentByte = data[i / 2];
        byte digit = (i % 2 == 0) ? (byte) ((currentByte & 0xff) >>> 4) : (byte) (currentByte & 0x0f);
        if (digit < 10) {
            digitStr.append(digit);
        }
    }

    if (signed) {
        byte sign = (byte) (data[len - 1] & 0x0f);
        if (sign == 0x0b || sign == 0x0d) {
            digitStr.insert(0, '-');
        }
    }

    return Long.parseLong(digitStr.toString());
}
 
开发者ID:raydac,项目名称:java-binary-block-parser,代码行数:22,代码来源:PackedBCDCustomFieldTest.java

示例4: readCustomFieldType

import com.igormaznitsa.jbbp.io.JBBPBitInputStream; //导入依赖的package包/类
@Override
public JBBPAbstractField readCustomFieldType(final JBBPBitInputStream in, final JBBPBitOrder bitOrder, final int parserFlags, final JBBPFieldTypeParameterContainer customTypeFieldInfo, JBBPNamedFieldInfo fieldName, int extraData, boolean readWholeStream, int arrayLength) throws IOException {
    final boolean signed = "sbcd".equals(customTypeFieldInfo.getTypeName());

    if (readWholeStream) {
        throw new UnsupportedOperationException("Whole stream reading unsupported");
    } else {
        if (arrayLength <= 0) {
            return new JBBPFieldLong(fieldName, readValueFromPackedDecimal(in, extraData, signed));
        } else {
            final long[] result = new long[arrayLength];
            for (int i = 0; i < arrayLength; i++) {
                result[i] = readValueFromPackedDecimal(in, extraData, signed);
            }
            return new JBBPFieldArrayLong(fieldName, result);
        }
    }
}
 
开发者ID:raydac,项目名称:java-binary-block-parser,代码行数:19,代码来源:PackedBCDCustomFieldTest.java

示例5: readCustomFieldType

import com.igormaznitsa.jbbp.io.JBBPBitInputStream; //导入依赖的package包/类
@Override
public JBBPAbstractField readCustomFieldType(final JBBPBitInputStream in, final JBBPBitOrder bitOrder, final int parserFlags, final JBBPFieldTypeParameterContainer customTypeFieldInfo, final JBBPNamedFieldInfo fieldName, final int extraData, final boolean readWholeStream, final int arrayLength) throws IOException {
    if (arrayLength < 0) {
        return new JBBPFieldInt(fieldName, readThreeBytesAsInt(in, customTypeFieldInfo.getByteOrder(), bitOrder));
    } else {
        if (readWholeStream) {
            final IntBuffer intBuffer = new IntBuffer(1024);
            while (in.hasAvailableData()) {
                intBuffer.put(readThreeBytesAsInt(in, customTypeFieldInfo.getByteOrder(), bitOrder));
            }
            return new JBBPFieldArrayInt(fieldName, intBuffer.toArray());
        } else {
            final int[] array = new int[arrayLength];
            for (int i = 0; i < arrayLength; i++) {
                array[i] = readThreeBytesAsInt(in, customTypeFieldInfo.getByteOrder(), bitOrder);
            }
            return new JBBPFieldArrayInt(fieldName, array);
        }
    }
}
 
开发者ID:raydac,项目名称:java-binary-block-parser,代码行数:21,代码来源:CustomThreeByteIntegerTypeTest.java

示例6: testGetFinalStreamByteCounter_SequentlyFromTheSameStream_WithEOFAtTheEnd

import com.igormaznitsa.jbbp.io.JBBPBitInputStream; //导入依赖的package包/类
@Test
public void testGetFinalStreamByteCounter_SequentlyFromTheSameStream_WithEOFAtTheEnd() throws Exception {
    final JBBPBitInputStream stream = new JBBPBitInputStream(new ByteArrayInputStream(new byte[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16}));
    final JBBPParser parser = JBBPParser.prepare("byte [5];");
    assertEquals(0L, parser.getFinalStreamByteCounter());
    parser.parse(stream);
    assertEquals(5, parser.getFinalStreamByteCounter());
    parser.parse(stream);
    assertEquals(10, parser.getFinalStreamByteCounter());
    parser.parse(stream);
    assertEquals(15, parser.getFinalStreamByteCounter());
    try {
        parser.parse(stream);
        fail("Must throw EOF");
    } catch (EOFException ex) {
        assertEquals(16, parser.getFinalStreamByteCounter());
    }
}
 
开发者ID:raydac,项目名称:java-binary-block-parser,代码行数:19,代码来源:JBBPParserTest.java

示例7: testCounterOfStreamAsParameter

import com.igormaznitsa.jbbp.io.JBBPBitInputStream; //导入依赖的package包/类
@Test
public void testCounterOfStreamAsParameter() throws Exception {
    final List<JBBPNamedFieldInfo> list = new ArrayList<JBBPNamedFieldInfo>();

    final byte[] compiled = new byte[]{0};
    final JBBPCompiledBlock compiledBlock = JBBPCompiledBlock.prepare().setCompiledData(compiled).setSource("none").setNamedFieldData(list).build();

    JBBPOnlyFieldEvaluator expr = new JBBPOnlyFieldEvaluator("$", -1);

    final JBBPBitInputStream inStream = new JBBPBitInputStream(new ByteArrayInputStream(new byte[]{1, 2, 3, 4, 5}));
    inStream.read();
    inStream.read();
    inStream.read();

    assertEquals(3, expr.eval(inStream, 0, compiledBlock, null));
}
 
开发者ID:raydac,项目名称:java-binary-block-parser,代码行数:17,代码来源:JBBPOnlyFieldEvaluatorTest.java

示例8: getSin

import com.igormaznitsa.jbbp.io.JBBPBitInputStream; //导入依赖的package包/类
private static String getSin(String folder, byte[] source) throws Exception {
 Collection<File> sinfiles = FileUtils.listFiles(new File(folder), new String[] {"sin"}, true);
 Iterator<File> ifiles = sinfiles.iterator();
 while (ifiles.hasNext()) {
  try {
	  SinFile  sinfile = new SinFile(ifiles.next());
	  if (sinfile.getVersion()!=4) {
		  JBBPBitInputStream sinStream = new JBBPBitInputStream(new FileInputStream(sinfile.getFile()));
		  byte[] res = sinStream.readByteArray(source.length);
		  if (Arrays.equals(source, res))
			  return sinfile.getShortName();
	  }
	  else {
		  if (Arrays.equals(source, sinfile.getHeader())) return sinfile.getFile().getName();
	  }
  } catch (EOFException eof) {
  }			  
 }
 return "Not identified";
}
 
开发者ID:Androxyde,项目名称:Flashtool,代码行数:21,代码来源:Parser.java

示例9: parseUnits

import com.igormaznitsa.jbbp.io.JBBPBitInputStream; //导入依赖的package包/类
public void parseUnits() throws IOException {
 unitList = new Vector<TAUnit>();
 JBBPParser unitblock = JBBPParser.prepare(
	    "         <int unitNumber;"
	           + "<int length;"
	           + "<int magic;"
	           + "<int unknown;"
    );
 
 JBBPBitInputStream unitsStream = new JBBPBitInputStream(new ByteArrayInputStream(units));
 try {
 while (unitsStream.hasAvailableData()) {
  TARawUnit rawunit = unitblock.parse(unitsStream).mapTo(TARawUnit.class);
  rawunit.fetchContent(unitsStream);
  if (rawunit.isValid()) unitList.add(rawunit.getUnit());
 }
 } catch (Exception ioe) {}
 unitsStream.close();
}
 
开发者ID:Androxyde,项目名称:Flashtool,代码行数:20,代码来源:TARawBlock.java

示例10: readVarArray

import com.igormaznitsa.jbbp.io.JBBPBitInputStream; //导入依赖的package包/类
@Override
public JBBPAbstractArrayField<? extends JBBPAbstractField> readVarArray(Object sourceStruct, JBBPBitInputStream inStream, JBBPByteOrder byteOrder, JBBPNamedFieldInfo nullableNamedFieldInfo, int extraValue, boolean readWholeStream, int arraySize) throws IOException {
    if (readWholeStream) {
        return new JBBPFieldArrayLong(nullableNamedFieldInfo, inStream.readLongArray(-1, byteOrder));
    } else {
        return new JBBPFieldArrayLong(nullableNamedFieldInfo, inStream.readLongArray(arraySize, byteOrder));
    }
}
 
开发者ID:raydac,项目名称:java-binary-block-parser,代码行数:9,代码来源:VarCustomImpl.java

示例11: testReadWrite

import com.igormaznitsa.jbbp.io.JBBPBitInputStream; //导入依赖的package包/类
@Test
public void testReadWrite() throws Exception {
    final VarCustomImpl impl = new VarCustomImpl();

    final byte[] etalonArray = new byte[319040];
    RND.nextBytes(etalonArray);
    impl.read(new JBBPBitInputStream(new ByteArrayInputStream(etalonArray)));

    final ByteArrayOutputStream bos = new ByteArrayOutputStream();
    final JBBPBitOutputStream bios = new JBBPBitOutputStream(bos);
    impl.write(bios);
    bios.close();

    assertArrayEquals(etalonArray, bos.toByteArray());
}
 
开发者ID:raydac,项目名称:java-binary-block-parser,代码行数:16,代码来源:VarCustomTest.java

示例12: eval

import com.igormaznitsa.jbbp.io.JBBPBitInputStream; //导入依赖的package包/类
@Override
public int eval(final JBBPBitInputStream inStream, final int currentCompiledBlockOffset, final JBBPCompiledBlock block, final JBBPNamedNumericFieldMap fieldMap) {
    return externalFieldName == null
            ? fieldMap.get(block.getNamedFields()[this.namedFieldIndex]).getAsInt()
            : this.externalFieldName.equals("$")
            ? (int) inStream.getCounter()
            : fieldMap.getExternalFieldValue(this.externalFieldName, block, this);
}
 
开发者ID:raydac,项目名称:java-binary-block-parser,代码行数:9,代码来源:JBBPOnlyFieldEvaluator.java

示例13: callRead

import com.igormaznitsa.jbbp.io.JBBPBitInputStream; //导入依赖的package包/类
protected Object callRead(final Object instance, final byte[] array) throws Exception {
    try {
        return this.callRead(instance, new JBBPBitInputStream(new ByteArrayInputStream(array)));
    } catch (InvocationTargetException ex) {
        if (ex.getCause() != null) {
            throw (Exception) ex.getCause();
        } else {
            throw ex;
        }
    }
}
 
开发者ID:raydac,项目名称:java-binary-block-parser,代码行数:12,代码来源:AbstractJBBPToJava6ConverterTest.java

示例14: assertResource

import com.igormaznitsa.jbbp.io.JBBPBitInputStream; //导入依赖的package包/类
public void assertResource(final String resourceName, final byte[] content) throws Exception {
    final InputStream in = getResourceAsInputStream(resourceName);
    try {
        final byte[] fileContent = new JBBPBitInputStream(in).readByteArray(-1);
        assertArrayEquals("Content of '" + resourceName + "'", fileContent, content);
    } finally {
        JBBPUtils.closeQuietly(in);
    }
}
 
开发者ID:raydac,项目名称:java-binary-block-parser,代码行数:10,代码来源:AbstractParserIntegrationTest.java

示例15: testReadThreeByteInteger_OneValue

import com.igormaznitsa.jbbp.io.JBBPBitInputStream; //导入依赖的package包/类
@Test
public void testReadThreeByteInteger_OneValue() throws Exception {
    final JBBPParser parser = JBBPParser.prepare("int24 value;", new Int24CustomTypeProcessor());
    final JBBPParser inverseparser = JBBPParser.prepare("<int24 value;", new Int24CustomTypeProcessor());
    assertEquals(0x010203, parser.parse(new byte[]{0x01, 0x02, 0x03}).findFieldForType(JBBPFieldInt.class).getAsInt());
    assertEquals(0x8040C0, parser.parse(new JBBPBitInputStream(new ByteArrayInputStream(new byte[]{0x01, 0x02, 0x03}), JBBPBitOrder.MSB0)).findFieldForType(JBBPFieldInt.class).getAsInt());
    assertEquals(0x030201, inverseparser.parse(new byte[]{0x01, 0x02, 0x03}).findFieldForType(JBBPFieldInt.class).getAsInt());
    assertEquals(0xC04080, inverseparser.parse(new JBBPBitInputStream(new ByteArrayInputStream(new byte[]{0x01, 0x02, 0x03}), JBBPBitOrder.MSB0)).findFieldForType(JBBPFieldInt.class).getAsInt());
}
 
开发者ID:raydac,项目名称:java-binary-block-parser,代码行数:10,代码来源:CustomThreeByteIntegerTypeTest.java


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