Changeset 1254


Ignore:
Timestamp:
Oct 22, 2010, 2:45:53 PM (11 years ago)
Author:
Nicklas Nordborg
Message:

Fixes possible NullPointerException:s that may happen if not all entries have data in the torrent file.

Location:
extensions/net.sf.basedb.torrent/trunk/src/external/hpbtc/hpbtc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/net.sf.basedb.torrent/trunk/src/external/hpbtc/hpbtc/protocol/torrent/Torrent.java

    r1248 r1254  
    33import hpbtc.bencoding.BencodingReader;
    44import hpbtc.bencoding.BencodingWriter;
     5import hpbtc.util.IOUtil;
    56import hpbtc.util.TorrentUtil;
    67import java.io.ByteArrayOutputStream;
     
    8384        }
    8485        if (meta.containsKey("comment".getBytes(byteEncoding))) {
    85             comment = new String((byte[]) meta.get("comment".getBytes(
    86                     byteEncoding)), byteEncoding);
     86            comment = IOUtil.toString((byte[])meta.get("comment".getBytes(byteEncoding)), byteEncoding);
    8787        }
    8888        if (meta.containsKey("created by".getBytes(byteEncoding))) {
    89             createdBy = new String((byte[]) meta.get("created by".getBytes(
    90                     byteEncoding)), byteEncoding);
     89            createdBy = IOUtil.toString((byte[])meta.get("created by".getBytes(byteEncoding)), byteEncoding);
    9190        }
    9291        if (meta.containsKey("encoding".getBytes(byteEncoding))) {
    93             encoding = new String((byte[]) meta.get("encoding".getBytes(
    94                     byteEncoding)), byteEncoding);
     92            encoding = IOUtil.toString((byte[])meta.get("encoding".getBytes(byteEncoding)), byteEncoding);
    9593        }
    9694        final boolean multiple =
  • extensions/net.sf.basedb.torrent/trunk/src/external/hpbtc/hpbtc/util/IOUtil.java

    r1248 r1254  
    88import java.io.IOException;
    99import java.io.RandomAccessFile;
     10import java.io.UnsupportedEncodingException;
    1011import java.net.InetSocketAddress;
    1112import java.nio.ByteBuffer;
     
    2122public class IOUtil {
    2223
     24 
     25  public static String toString(byte[] bytes, String encoding)
     26    throws UnsupportedEncodingException
     27  {
     28    return bytes == null ? null : new String(bytes, encoding);
     29  }
     30
     31 
    2332    public static InetSocketAddress getAddress(final SocketChannel c) {
    2433        return (InetSocketAddress) c.socket().getRemoteSocketAddress();
Note: See TracChangeset for help on using the changeset viewer.