Package com.torrent4j.storage

Source Code of com.torrent4j.storage.AbstractTorrentStorage

package com.torrent4j.storage;

import java.io.IOException;
import java.nio.ByteBuffer;

import com.torrent4j.model.TorrentPiece;
import com.torrent4j.util.Hash;

/**
* Abstract {@link TorrentStorage} that implements universal that methods that
* very likely don't need to be override by implementations.
*
* @author <a href="http://www.rogiel.com">Rogiel</a>
*/
public abstract class AbstractTorrentStorage implements TorrentStorage {
  @Override
  public Hash checksum(TorrentPiece piece) throws IOException {
    final ByteBuffer buffer = read(piece.getTorrent(),
        piece.getTorrentRange());
    if (buffer == null)
      return null;
    return new Hash(piece.getHash().getType(), piece.getHash().getType()
        .hash(buffer));
  }
}
TOP

Related Classes of com.torrent4j.storage.AbstractTorrentStorage

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.