📄 localetorrentutil.java
字号:
// Decompiled by Jad v1.5.8e2. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://kpdus.tripod.com/jad.html
// Decompiler options: packimports(3) fieldsfirst ansi space
// Source File Name: LocaleTorrentUtil.java
package org.gudy.azureus2.core3.internat;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import java.nio.charset.CharsetDecoder;
import java.util.*;
import org.gudy.azureus2.core3.torrent.*;
import org.gudy.azureus2.core3.util.Debug;
import org.gudy.azureus2.core3.util.TorrentUtils;
// Referenced classes of package org.gudy.azureus2.core3.internat:
// LocaleUtil, LocaleUtilDecoder, LocaleUtilDecoderCandidate, LocaleUtilDecoderFallback,
// LocaleUtilEncodingException, LocaleUtilListener
public class LocaleTorrentUtil
{
private static List listeners = new ArrayList();
public LocaleTorrentUtil()
{
}
public static LocaleUtilDecoder getTorrentEncodingIfAvailable(TOTorrent torrent)
throws TOTorrentException, UnsupportedEncodingException
{
String encoding = torrent.getAdditionalStringProperty("encoding");
if (encoding == null)
return null;
String canonical_name;
try
{
canonical_name = Charset.forName(encoding).name();
}
catch (Throwable e)
{
canonical_name = encoding;
}
LocaleUtilDecoder chosenDecoder = null;
LocaleUtilDecoder all_decoders[] = LocaleUtil.getSingleton().getDecoders();
int i = 0;
do
{
if (i >= all_decoders.length)
break;
if (all_decoders[i].getName().equals(canonical_name))
{
chosenDecoder = all_decoders[i];
break;
}
i++;
} while (true);
return chosenDecoder;
}
public static LocaleUtilDecoder getTorrentEncoding(TOTorrent torrent)
throws TOTorrentException, UnsupportedEncodingException
{
String encoding;
boolean bSaveToFile;
Throwable e;
encoding = torrent.getAdditionalStringProperty("encoding");
try
{
TorrentUtils.getTorrentFileName(torrent);
bSaveToFile = true;
}
// Misplaced declaration of an exception variable
catch (Throwable e)
{
bSaveToFile = false;
}
if (encoding == null)
break MISSING_BLOCK_LABEL_114;
LocaleUtilDecoder all_decoders[];
String canonical_name;
int i;
all_decoders = LocaleUtil.getSingleton().getDecoders();
LocaleUtilDecoder fallback_decoder = LocaleUtil.getSingleton().getFallBackDecoder();
canonical_name = encoding.equals(fallback_decoder.getName()) ? encoding : Charset.forName(encoding).name();
i = 0;
_L1:
if (i >= all_decoders.length)
break MISSING_BLOCK_LABEL_114;
if (all_decoders[i].getName().equals(canonical_name))
return all_decoders[i];
i++;
goto _L1
all_decoders;
Debug.printStackTrace(all_decoders);
LocaleUtilDecoderCandidate candidates[] = getTorrentCandidates(torrent);
boolean system_decoder_is_valid = false;
LocaleUtil localeUtil = LocaleUtil.getSingleton();
LocaleUtilDecoder system_decoder = localeUtil.getSystemDecoder();
int i = 0;
do
{
if (i >= candidates.length)
break;
if (candidates[i].getDecoder() == system_decoder)
{
system_decoder_is_valid = true;
break;
}
i++;
} while (true);
LocaleUtilDecoder selected_decoder = null;
int i = 0;
do
{
if (i >= listeners.size())
break;
LocaleUtilDecoderCandidate candidate = null;
try
{
candidate = ((LocaleUtilListener)listeners.get(i)).selectDecoder(localeUtil, torrent, candidates);
}
catch (LocaleUtilEncodingException e) { }
if (candidate != null)
{
selected_decoder = candidate.getDecoder();
break;
}
bSaveToFile = false;
i++;
} while (true);
if (selected_decoder == null)
if (system_decoder_is_valid)
selected_decoder = localeUtil.getSystemDecoder();
else
selected_decoder = localeUtil.getFallBackDecoder();
torrent.setAdditionalStringProperty("encoding", selected_decoder.getName());
if (bSaveToFile)
TorrentUtils.writeToFile(torrent);
return selected_decoder;
}
protected static LocaleUtilDecoderCandidate[] getTorrentCandidates(TOTorrent torrent)
throws TOTorrentException, UnsupportedEncodingException
{
Set cand_set = new HashSet();
LocaleUtil localeUtil = LocaleUtil.getSingleton();
List candidateDecoders = localeUtil.getCandidateDecoders(torrent.getName());
long lMinCandidates = candidateDecoders.size();
byte minCandidatesArray[] = torrent.getName();
cand_set.addAll(candidateDecoders);
TOTorrentFile files[] = torrent.getFiles();
for (int i = 0; i < files.length; i++)
{
TOTorrentFile file = files[i];
byte comps[][] = file.getPathComponents();
for (int j = 0; j < comps.length; j++)
{
candidateDecoders = localeUtil.getCandidateDecoders(comps[j]);
if ((long)candidateDecoders.size() < lMinCandidates)
{
lMinCandidates = candidateDecoders.size();
minCandidatesArray = comps[j];
}
cand_set.retainAll(candidateDecoders);
}
}
byte comment[] = torrent.getComment();
if (comment != null)
{
candidateDecoders = localeUtil.getCandidateDecoders(comment);
if ((long)candidateDecoders.size() < lMinCandidates)
{
lMinCandidates = candidateDecoders.size();
minCandidatesArray = comment;
}
cand_set.retainAll(candidateDecoders);
}
byte created[] = torrent.getCreatedBy();
if (created != null)
{
candidateDecoders = localeUtil.getCandidateDecoders(created);
if ((long)candidateDecoders.size() < lMinCandidates)
{
lMinCandidates = candidateDecoders.size();
minCandidatesArray = created;
}
cand_set.retainAll(candidateDecoders);
}
List candidatesList = localeUtil.getCandidatesAsList(minCandidatesArray);
LocaleUtilDecoderCandidate candidates[] = new LocaleUtilDecoderCandidate[candidatesList.size()];
candidatesList.toArray(candidates);
Arrays.sort(candidates, new Comparator() {
public int compare(Object o1, Object o2)
{
LocaleUtilDecoderCandidate luc1 = (LocaleUtilDecoderCandidate)o1;
LocaleUtilDecoderCandidate luc2 = (LocaleUtilDecoderCandidate)o2;
return luc1.getDecoder().getIndex() - luc2.getDecoder().getIndex();
}
});
return candidates;
}
public static void setTorrentEncoding(TOTorrent torrent, String encoding)
throws LocaleUtilEncodingException
{
try
{
LocaleUtil localeUtil = LocaleUtil.getSingleton();
LocaleUtilDecoderCandidate candidates[] = getTorrentCandidates(torrent);
String canonical_requested_name;
if (encoding.equalsIgnoreCase("system"))
canonical_requested_name = localeUtil.getSystemEncoding();
else
if (encoding.equalsIgnoreCase(LocaleUtilDecoderFallback.NAME))
{
canonical_requested_name = LocaleUtilDecoderFallback.NAME;
} else
{
CharsetDecoder requested_decoder = Charset.forName(encoding).newDecoder();
canonical_requested_name = requested_decoder.charset().name();
}
boolean ok = false;
int i = 0;
do
{
if (i >= candidates.length)
break;
if (candidates[i].getDecoder().getName().equals(canonical_requested_name))
{
ok = true;
break;
}
i++;
} while (true);
if (!ok)
{
String charsets[] = new String[candidates.length];
String names[] = new String[candidates.length];
for (int i = 0; i < candidates.length; i++)
{
LocaleUtilDecoder decoder = candidates[i].getDecoder();
charsets[i] = decoder.getName();
names[i] = decoder.decodeString(torrent.getName());
}
throw new LocaleUtilEncodingException(charsets, names);
}
torrent.setAdditionalStringProperty("encoding", canonical_requested_name);
}
catch (Throwable e)
{
if (e instanceof LocaleUtilEncodingException)
throw (LocaleUtilEncodingException)e;
else
throw new LocaleUtilEncodingException(e);
}
}
public static void setDefaultTorrentEncoding(TOTorrent torrent)
throws LocaleUtilEncodingException
{
setTorrentEncoding(torrent, "UTF8");
}
public static String getCurrentTorrentEncoding(TOTorrent torrent)
{
return torrent.getAdditionalStringProperty("encoding");
}
public static void addListener(LocaleUtilListener l)
{
listeners.add(l);
}
public static void removeListener(LocaleUtilListener l)
{
listeners.remove(l);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -