Skip to content

Commit

Permalink
Propagating borrowObject's Exception as a RuntimeException
Browse files Browse the repository at this point in the history
  • Loading branch information
zanella committed Nov 23, 2016
1 parent 3b6ed17 commit 0f1356d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,12 @@ public ByteBufferPool(int amount, int length) {
pool = new GenericObjectPool<ByteBuffer>(new ByteBufferFactory(length), gopc);
}

public ByteBuffer borrowObject() throws Exception {
return pool.borrowObject();
public ByteBuffer borrowObject() {
try {
return pool.borrowObject();
} catch (Exception e) {
throw new RuntimeException(e);
}
}

public void returnObject(ByteBuffer buffer) {
Expand Down
14 changes: 7 additions & 7 deletions core/src/main/java/com/turn/ttorrent/common/Torrent.java
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ public static Torrent load(File torrent, boolean seeder)
* torrent's creator.
*/
public static Torrent create(File source, URI announce, String createdBy)
throws InterruptedException, IOException, NoSuchAlgorithmException, Exception {
throws InterruptedException, IOException, NoSuchAlgorithmException {
return Torrent.create(source, null, DEFAULT_PIECE_LENGTH,
announce, null, createdBy);
}
Expand All @@ -528,7 +528,7 @@ public static Torrent create(File source, URI announce, String createdBy)
* torrent's creator.
*/
public static Torrent create(File parent, List<File> files, URI announce,
String createdBy) throws InterruptedException, IOException, NoSuchAlgorithmException, Exception {
String createdBy) throws InterruptedException, IOException, NoSuchAlgorithmException {
return Torrent.create(parent, files, DEFAULT_PIECE_LENGTH,
announce, null, createdBy);
}
Expand All @@ -549,7 +549,7 @@ public static Torrent create(File parent, List<File> files, URI announce,
* torrent's creator.
*/
public static Torrent create(File source, int pieceLength, List<List<URI>> announceList,
String createdBy) throws InterruptedException, IOException, NoSuchAlgorithmException, Exception {
String createdBy) throws InterruptedException, IOException, NoSuchAlgorithmException {
return Torrent.create(source, null, pieceLength,
null, announceList, createdBy);
}
Expand All @@ -574,7 +574,7 @@ public static Torrent create(File source, int pieceLength, List<List<URI>> annou
*/
public static Torrent create(File source, List<File> files, int pieceLength,
List<List<URI>> announceList, String createdBy)
throws InterruptedException, IOException, NoSuchAlgorithmException, Exception {
throws InterruptedException, IOException, NoSuchAlgorithmException {
return Torrent.create(source, files, pieceLength,
null, announceList, createdBy);
}
Expand All @@ -600,7 +600,7 @@ public static Torrent create(File source, List<File> files, int pieceLength,
*/
private static Torrent create(File parent, List<File> files, int pieceLength,
URI announce, List<List<URI>> announceList, String createdBy)
throws InterruptedException, IOException, NoSuchAlgorithmException, Exception {
throws InterruptedException, IOException, NoSuchAlgorithmException {
if (files == null || files.isEmpty()) {
logger.info("Creating single-file torrent for {}...",
parent.getName());
Expand Down Expand Up @@ -715,12 +715,12 @@ public String call() throws UnsupportedEncodingException, InterruptedException {
* @param file The file to hash.
*/
private static String hashFile(File file, int pieceLength)
throws InterruptedException, IOException, NoSuchAlgorithmException, Exception {
throws InterruptedException, IOException, NoSuchAlgorithmException {
return Torrent.hashFiles(Arrays.asList(new File[] { file }), pieceLength);
}

private static String hashFiles(List<File> files, int pieceLength)
throws InterruptedException, IOException, NoSuchAlgorithmException, Exception {
throws InterruptedException, IOException, NoSuchAlgorithmException {
int threads = getHashingThreadsCount();
ExecutorService executor = Executors.newFixedThreadPool(threads);
final ByteBufferPool bbp = new ByteBufferPool(threads + 1, pieceLength);
Expand Down

0 comments on commit 0f1356d

Please sign in to comment.