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

The following examples show how to use com.igormaznitsa.jbbp.io.JBBPBitInputStream#close() . 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: TARawBlock.java    From Flashtool with GNU General Public License v3.0 6 votes vote down vote up
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(new TARawUnit());
  rawunit.fetchContent(unitsStream);
  if (rawunit.isValid()) unitList.add(rawunit.getUnit());
 }
 } catch (Exception ioe) {}
 unitsStream.close();
}
 
Example 2
Source File: ZXEMLSnapshotFormatTest.java    From zxpoly with GNU General Public License v3.0 5 votes vote down vote up
private static byte [] loadResource(final String name) throws Exception {
  final InputStream ins = ZXEMLSnapshotFormatTest.class.getResourceAsStream(name);
  assertNotNull("Can't find resource "+name,ins);
  final JBBPBitInputStream in = new JBBPBitInputStream(ins);
  final byte [] result = in.readByteArray(-1);
  in.close();
  return result;
}
 
Example 3
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 4
Source File: CommandFlasher.java    From Flashtool with GNU General Public License v3.0 5 votes vote down vote up
public void getUfsInfo()  throws IOException,X10FlashException {
   	logger.info("Sending Get-ufs-info");
   		String command = "Get-ufs-info";
   		USBFlash.write(command.getBytes());
   		CommandPacket reply = USBFlash.readCommandReply(true);
   		logger.info("   Get-ufs-info status : "+reply.getResponse());

   		JBBPParser ufs_parser = JBBPParser.prepare(
   			    "byte headerlen;"
                 + "byte[headerlen-1] ufs_header;"
                 + "luns [_] { "
                 + "   byte lunlength; "
                 + "   byte reserved1; "
                 + "   byte lunid; "
                 + "   byte[12] reserved2; "
                 + "   int length; "
                 + "   byte[lunlength-19] lundata; "
                 + "}"
            );		

   		try {
   			System.out.println(HexDump.toHex(reply.getDataArray()));
   			JBBPBitInputStream stream = new JBBPBitInputStream(new ByteArrayInputStream(reply.getDataArray()));
   			ufs_infos = ufs_parser.parse(stream).mapTo(new UfsInfos());
   			ufs_infos.setSectorSize(Integer.parseInt(getPhoneProperty("Sector-size")));
   			try {
   			   stream.close();
   			} catch (Exception streamclose ) {}
   		}
   		catch (Exception e) {
   			System.out.println(e.getMessage());
   			ufs_infos=null;
   		}

}