Esempio n. 1
0
 /** Ecrit dans le fichier la pièce piece de numeros num */
 public void writePiece(byte[] piece, int num) {
   if (_iscomplete) {
     throw new IllegalArgumentException();
   } else {
     this.writePieceTmpFile(piece, num);
     _buffermap.setBit(num, true);
   }
 }
Esempio n. 2
0
  /** Lis le header du fichier temporaire et charge ses informations */
  private void readHeaderTmpFile() {
    try {
      FileInputStream reader_tmp = new FileInputStream(this);
      FileChannel reader = reader_tmp.getChannel();

      int key_size = 0;
      int offset = 0;

      // Taile de le clef
      key_size = Tools.readInt(reader, offset);
      offset += 4;
      // Clef
      _key = Tools.readString(reader, offset, key_size);
      offset += key_size;
      // Size
      _size = Tools.readInt(reader, offset);
      offset += 4;
      // piecesize
      _piecesize = Tools.readInt(reader, offset);
      offset += 4;
      // Buffermap
      _buffermap = new Buffermap(this.nbPieces(), false);
      int i;
      for (i = 0; i < this.nbPieces(); i++) {
        int index = Tools.readInt(reader, offset);
        if (index >= 0) {
          _buffermap.setBit(i, true);
        } else {
          _buffermap.setBit(i, false);
        }
        offset += 4;
      }

      reader_tmp.close();
    } catch (Exception e) {
      System.out.println("Unable to read tmp file header");
      e.printStackTrace();
    }
  }