* remove annoying logging

This commit is contained in:
Reinhard Pointner 2012-06-01 02:31:17 +00:00
parent c40c53c53c
commit be08a2a050
1 changed files with 20 additions and 25 deletions

View File

@ -13,8 +13,6 @@ import java.util.Collections;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
public class Torrent { public class Torrent {
@ -31,23 +29,20 @@ public class Torrent {
private final boolean singleFileTorrent; private final boolean singleFileTorrent;
public Torrent(File torrent) throws IOException { public Torrent(File torrent) throws IOException {
this(decodeTorrent(torrent)); this(decodeTorrent(torrent));
} }
public Torrent(Map<?, ?> torrentMap) { public Torrent(Map<?, ?> torrentMap) {
Charset charset = Charset.forName("UTF-8"); Charset charset = Charset.forName("UTF-8");
encoding = decodeString(torrentMap.get("encoding"), charset); encoding = decodeString(torrentMap.get("encoding"), charset);
try { try {
charset = Charset.forName(encoding); charset = Charset.forName(encoding);
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
// invalid encoding, just keep using UTF-8 // invalid encoding, just keep using UTF-8
Logger.getLogger(getClass().getName()).log(Level.WARNING, "Invalid encoding: " + encoding);
} }
createdBy = decodeString(torrentMap.get("created by"), charset); createdBy = decodeString(torrentMap.get("created by"), charset);
@ -100,7 +95,7 @@ public class Torrent {
} }
} }
private static Map<?, ?> decodeTorrent(File torrent) throws IOException { private static Map<?, ?> decodeTorrent(File torrent) throws IOException {
InputStream in = new BufferedInputStream(new FileInputStream(torrent)); InputStream in = new BufferedInputStream(new FileInputStream(torrent));
@ -111,7 +106,7 @@ public class Torrent {
} }
} }
private String decodeString(Object byteArray, Charset charset) { private String decodeString(Object byteArray, Charset charset) {
if (byteArray == null) if (byteArray == null)
return null; return null;
@ -119,7 +114,7 @@ public class Torrent {
return new String((byte[]) byteArray, charset); return new String((byte[]) byteArray, charset);
} }
private Long decodeLong(Object number) { private Long decodeLong(Object number) {
if (number == null) if (number == null)
return null; return null;
@ -127,82 +122,82 @@ public class Torrent {
return (Long) number; return (Long) number;
} }
public String getAnnounce() { public String getAnnounce() {
return announce; return announce;
} }
public String getComment() { public String getComment() {
return comment; return comment;
} }
public String getCreatedBy() { public String getCreatedBy() {
return createdBy; return createdBy;
} }
public Long getCreationDate() { public Long getCreationDate() {
return creationDate; return creationDate;
} }
public String getEncoding() { public String getEncoding() {
return encoding; return encoding;
} }
public List<Entry> getFiles() { public List<Entry> getFiles() {
return files; return files;
} }
public String getName() { public String getName() {
return name; return name;
} }
public Long getPieceLength() { public Long getPieceLength() {
return pieceLength; return pieceLength;
} }
public boolean isSingleFileTorrent() { public boolean isSingleFileTorrent() {
return singleFileTorrent; return singleFileTorrent;
} }
public static class Entry { public static class Entry {
private final String path; private final String path;
private final long length; private final long length;
public Entry(String path, long length) { public Entry(String path, long length) {
this.path = path; this.path = path;
this.length = length; this.length = length;
} }
public String getPath() { public String getPath() {
return path; return path;
} }
public String getName() { public String getName() {
// the last element in the path is the filename // the last element in the path is the filename
// torrents don't contain directory entries, so there is always a non-empty name // torrents don't contain directory entries, so there is always a non-empty name
return path.substring(path.lastIndexOf("/") + 1); return path.substring(path.lastIndexOf("/") + 1);
} }
public long getLength() { public long getLength() {
return length; return length;
} }
@Override @Override
public String toString() { public String toString() {
return getPath(); return getPath();