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 ("");
}
}
Aggregations