Search in sources :

Example 1 with LocaleUtil

use of com.biglybt.core.internat.LocaleUtil in project BiglyBT by BiglySoftware.

the class TOTorrentFileImpl method getRelativePath.

@Override
public String getRelativePath() {
    if (torrent == null) {
        return "";
    }
    byte[][] pathComponentsUTF8 = getPathComponentsUTF8();
    if (pathComponentsUTF8 != null) {
        StringBuilder sRelativePathSB = null;
        for (int j = 0; j < pathComponentsUTF8.length; j++) {
            try {
                String comp;
                try {
                    comp = new String(pathComponentsUTF8[j], "utf8");
                } catch (UnsupportedEncodingException e) {
                    System.out.println("file - unsupported encoding!!!!");
                    comp = "UnsupportedEncoding";
                }
                comp = FileUtil.convertOSSpecificChars(comp, j != pathComponentsUTF8.length - 1);
                if (j == 0) {
                    if (pathComponentsUTF8.length == 1) {
                        return (comp);
                    } else {
                        sRelativePathSB = new StringBuilder(512);
                    }
                } else {
                    sRelativePathSB.append(File.separator);
                }
                sRelativePathSB.append(comp);
            } catch (Exception ex) {
                Debug.out(ex);
            }
        }
        return sRelativePathSB == null ? "" : sRelativePathSB.toString();
    }
    LocaleUtilDecoder decoder = null;
    try {
        decoder = LocaleTorrentUtil.getTorrentEncodingIfAvailable(torrent);
        if (decoder == null) {
            LocaleUtil localeUtil = LocaleUtil.getSingleton();
            decoder = localeUtil.getSystemDecoder();
        }
    } catch (Exception e) {
    // Do Nothing
    }
    if (decoder != null) {
        StringBuilder sRelativePathSB = null;
        byte[][] components = getPathComponents();
        for (int j = 0; j < components.length; j++) {
            try {
                String comp;
                try {
                    comp = decoder.decodeString(components[j]);
                } catch (UnsupportedEncodingException e) {
                    System.out.println("file - unsupported encoding!!!!");
                    try {
                        comp = new String(components[j]);
                    } catch (Exception e2) {
                        comp = "UnsupportedEncoding";
                    }
                }
                comp = FileUtil.convertOSSpecificChars(comp, j != components.length - 1);
                if (j == 0) {
                    if (components.length == 1) {
                        return (comp);
                    } else {
                        sRelativePathSB = new StringBuilder(512);
                    }
                } else {
                    sRelativePathSB.append(File.separator);
                }
                sRelativePathSB.append(comp);
            } catch (Exception ex) {
                Debug.out(ex);
            }
        }
        return sRelativePathSB == null ? "" : sRelativePathSB.toString();
    } else {
        return ("");
    }
}
Also used : LocaleUtil(com.biglybt.core.internat.LocaleUtil) LocaleUtilDecoder(com.biglybt.core.internat.LocaleUtilDecoder) UnsupportedEncodingException(java.io.UnsupportedEncodingException) TOTorrentException(com.biglybt.core.torrent.TOTorrentException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Aggregations

LocaleUtil (com.biglybt.core.internat.LocaleUtil)1 LocaleUtilDecoder (com.biglybt.core.internat.LocaleUtilDecoder)1 TOTorrentException (com.biglybt.core.torrent.TOTorrentException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1