@Override public byte[] getPiece(int piece) throws IOException { if (!bitfield.getPiece(piece)) { return null; } byte[] bs = new byte[metainfo.getPieceSize(piece)]; getUncheckedPiece(piece, bs); return bs; }
@Override public List<Integer> missingSubpieces(int piece) { List<Integer> result = new ArrayList<Integer>(); int subpiece; if (bitfield.getPiece(piece)) { System.out.println("bug"); } for (int i = 0; i < BitField.NUM_SUBPIECES_PER_PIECE; i++) { subpiece = piece * BitField.NUM_SUBPIECES_PER_PIECE + i; if (!bitfield.get(subpiece)) { result.add(subpiece); } if (subpiece == metainfo.getnbSubpieces() - 1) { return result; } } return result; }
/** * Returns a byte array containing the requested piece or null if the storage doesn't contain the * piece yet. */ @Override public Map<Integer, byte[]> getSubpieces(int piece) throws IOException { if (!bitfield.getPiece(piece)) { return null; } Map<Integer, byte[]> result = new HashMap<Integer, byte[]>(); int subpiece; for (int i = 0; i < BitField.NUM_SUBPIECES_PER_PIECE; i++) { subpiece = piece * BitField.NUM_SUBPIECES_PER_PIECE + i; byte[] bs = new byte[metainfo.getSubpieceSize(subpiece)]; getUncheckedSubPiece(subpiece, bs, 0); result.put(subpiece, bs); if (subpiece == metainfo.getnbSubpieces() - 1) { return result; } } return result; }