Java Code Examples for com.igormaznitsa.jbbp.io.JBBPBitInputStream#readInt()

The following examples show how to use com.igormaznitsa.jbbp.io.JBBPBitInputStream#readInt() . 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: SessionData.java    From zxpoly with GNU General Public License v3.0 6 votes vote down vote up
public SessionData(final JBBPBitInputStream inStream) throws IOException {
  baseAddress = inStream.readInt(JBBPByteOrder.BIG_ENDIAN);
  showGrid = inStream.readBoolean();
  showColumns = inStream.readBoolean();
  zxAddressing = inStream.readBoolean();
  invertBase = inStream.readBoolean();
  mode512x384 = inStream.readBoolean();
  columnNumber = inStream.readInt(JBBPByteOrder.BIG_ENDIAN);
  attributeMode =
      EditorComponent.AttributeMode.values()[inStream.readInt(JBBPByteOrder.BIG_ENDIAN)];
  zoom = inStream.readInt(JBBPByteOrder.BIG_ENDIAN);

  extraProperties = new Properties();

  if (inStream.hasAvailableData()) {
    final int extraDataLength = inStream.readInt(JBBPByteOrder.BIG_ENDIAN);
    final byte[] propertyData = inStream.readByteArray(extraDataLength);
    final Properties properties = new Properties();
    properties.load(new StringReader(new String(propertyData, StandardCharsets.UTF_8)));
    properties.stringPropertyNames().forEach(name -> {
      this.extraProperties.put(name, properties.getProperty(name));
    });
  }
}
 
Example 2
Source File: Info.java    From zxpoly with GNU General Public License v3.0 5 votes vote down vote up
public Info(final InputStream in) throws IOException {
  final JBBPBitInputStream bitin = new JBBPBitInputStream(in);
  this.name = new String(bitin.readByteArray(bitin.readByte()), StandardCharsets.US_ASCII);
  this.type = (char) bitin.readUnsignedShort(JBBPByteOrder.BIG_ENDIAN);
  this.startAddress = bitin.readInt(JBBPByteOrder.BIG_ENDIAN);
  this.length = bitin.readInt(JBBPByteOrder.BIG_ENDIAN);
  this.offset = bitin.readInt(JBBPByteOrder.BIG_ENDIAN);

  this.extra = bitin.readByteArray(bitin.readInt(JBBPByteOrder.BIG_ENDIAN));
}
 
Example 3
Source File: SZEPlugin.java    From zxpoly with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ReadResult readFrom(final File file, final int index) throws IOException {
  try (FileInputStream inStream = new FileInputStream(file)) {
    final ZXPolyData zxpolyData =
        new ZXPolyData(inStream, this.context.getComponents(AbstractFilePlugin.class));
    final JBBPBitInputStream in = new JBBPBitInputStream(inStream);
    final int length = in.readInt(JBBPByteOrder.BIG_ENDIAN);
    return new ReadResult(zxpolyData, new SessionData(in));
  }
}
 
Example 4
Source File: S1Packet.java    From Flashtool with GNU General Public License v3.0 5 votes vote down vote up
public TAUnit getTA() {
	try {
		JBBPBitInputStream taStream = new JBBPBitInputStream(new ByteArrayInputStream(data));
		int unit=taStream.readInt(JBBPByteOrder.BIG_ENDIAN);
		int talength = taStream.readInt(JBBPByteOrder.BIG_ENDIAN);
		TAUnit u = new TAUnit(unit, taStream.readByteArray(talength));
		taStream.close();
		return u;
	} catch (Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
Example 5
Source File: SinParser.java    From Flashtool with GNU General Public License v3.0 5 votes vote down vote up
public void parseHash(JBBPBitInputStream sinStream) throws IOException {
 JBBPParser hashBlocksV2 = JBBPParser.prepare(
           "block[_] {int offset;"
                   + "int length;"
                   + "byte hashLen;"
                   + "byte[hashLen] crc;}"
 );
 if (hashLen>0) {
  byte[] hashBlocks = sinStream.readByteArray(hashLen);
  blocks = hashBlocksV2.parse(hashBlocks).mapTo(new org.sinfile.parsers.v2.HashBlocks());
  certLen = sinStream.readInt(JBBPByteOrder.BIG_ENDIAN);
  cert = sinStream.readByteArray(certLen);
  if (blocks.block.length==1 && blocks.block[0].offset!=0) blocks.block[0].offset=0;
  if (blocks.block[0].length==16) {
	  partitioninfo = sinStream.readByteArray(16);
	  JBBPParser partInfo = JBBPParser.prepare(
	            "<int mot1;"
	          + "<int mot2;"
	          + "<int offset;"
	          + "<int blockcount;"
	  );
	  parti = partInfo.parse(partitioninfo).mapTo(new org.sinfile.parsers.v1.PartitionInfo());
	  if (blocks.block.length>1)
		  dataSize=parti.blockcount*blocks.block[1].length;
  }
  blocks.setSpare(this.payloadType);
 }
 dataType=getDataTypePriv();
}
 
Example 6
Source File: SinParser.java    From Flashtool with GNU General Public License v3.0 5 votes vote down vote up
public void parseHash(JBBPBitInputStream sinStream) throws IOException {
 JBBPParser hashBlocksV2 = JBBPParser.prepare(
           "block[_] {int offset;"
                   + "int length;"
                   + "byte hashLen;"
                   + "byte[hashLen] crc;}"
 );
 if (hashLen>0) {
  byte[] hashBlocks = sinStream.readByteArray(hashLen);
  blocks = hashBlocksV2.parse(hashBlocks).mapTo(new org.sinfile.parsers.v2.HashBlocks());
  certLen = sinStream.readInt(JBBPByteOrder.BIG_ENDIAN);
  cert = sinStream.readByteArray(certLen);
  if (blocks.block.length==1 && blocks.block[0].offset!=0) blocks.block[0].offset=0; 
  if (blocks.block[0].length==16) {
	  byte[] partinfo = sinStream.readByteArray(16);
	  JBBPParser partInfo = JBBPParser.prepare(
	            "<int mot1;"
	          + "<int mot2;"
	          + "<int offset;"
	          + "<int blockcount;"
	  );
	  parti = partInfo.parse(partinfo).mapTo(new org.sinfile.parsers.v1.PartitionInfo());
  }
 }
 dataType=getDataTypePriv();
 dataSize = getDataSizePriv();
}
 
Example 7
Source File: SinParser.java    From Flashtool with GNU General Public License v3.0 5 votes vote down vote up
public void parseHash(JBBPBitInputStream sinStream) throws IOException {

		  hashBlocks = sinStream.readByteArray(hashLen);
		  certLen = sinStream.readInt(JBBPByteOrder.BIG_ENDIAN);
		  cert = sinStream.readByteArray(certLen);
		  
		  JBBPParser hashBlocksV3 = JBBPParser.prepare(
		            "blocks[_] {int length;"
	              + "byte["+hashv3len[hashType]+"] crc;}"
	      );
		  blocks = hashBlocksV3.parse(hashBlocks).mapTo(new org.sinfile.parsers.v3.HashBlocks());

	  }