Ejemplo n.º 1
0
 private void loadNextBlock() {
   while (true) {
     try {
       if (!fileIt.hasNext() && (currentFileStream == null || currentFileStream.available() < 1))
         break;
     } catch (IOException e) {
       currentFileStream = null;
       if (!fileIt.hasNext()) break;
     }
     while (true) {
       try {
         if (currentFileStream != null && currentFileStream.available() > 0) break;
       } catch (IOException e1) {
         currentFileStream = null;
       }
       if (!fileIt.hasNext()) {
         nextBlock = null;
         currentFileStream = null;
         return;
       }
       try {
         currentFileStream = new FileInputStream(fileIt.next());
       } catch (FileNotFoundException e) {
         currentFileStream = null;
       }
     }
     try {
       int nextChar = currentFileStream.read();
       while (nextChar != -1) {
         if (nextChar != ((params.getPacketMagic() >>> 24) & 0xff)) {
           nextChar = currentFileStream.read();
           continue;
         }
         nextChar = currentFileStream.read();
         if (nextChar != ((params.getPacketMagic() >>> 16) & 0xff)) continue;
         nextChar = currentFileStream.read();
         if (nextChar != ((params.getPacketMagic() >>> 8) & 0xff)) continue;
         nextChar = currentFileStream.read();
         if (nextChar == (params.getPacketMagic() & 0xff)) break;
       }
       byte[] bytes = new byte[4];
       currentFileStream.read(bytes, 0, 4);
       long size = Utils.readUint32BE(Utils.reverseBytes(bytes), 0);
       // We allow larger than MAX_BLOCK_SIZE because test code uses this as well.
       if (size > Block.MAX_BLOCK_SIZE * 2 || size <= 0) continue;
       bytes = new byte[(int) size];
       currentFileStream.read(bytes, 0, (int) size);
       try {
         nextBlock = new Block(params, bytes);
       } catch (ProtocolException e) {
         nextBlock = null;
         continue;
       }
       break;
     } catch (IOException e) {
       currentFileStream = null;
       continue;
     }
   }
 }
Ejemplo n.º 2
0
 /** Creates a scriptPubKey for the given redeem script. */
 public static Script createP2SHOutputScript(Script redeemScript) {
   byte[] hash = Utils.sha256hash160(redeemScript.getProgram());
   return ScriptBuilder.createP2SHOutputScript(hash);
 }