Use java.nio.charset.StandardCharsets.* instead of Charset.forName
This commit is contained in:
parent
022c2c40a3
commit
4fae01236a
|
@ -1,5 +1,6 @@
|
||||||
package net.filebot;
|
package net.filebot;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
import static net.filebot.Logging.*;
|
import static net.filebot.Logging.*;
|
||||||
import static net.filebot.Settings.*;
|
import static net.filebot.Settings.*;
|
||||||
import static net.filebot.util.FileUtilities.*;
|
import static net.filebot.util.FileUtilities.*;
|
||||||
|
@ -8,7 +9,6 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.nio.channels.FileLock;
|
import java.nio.channels.FileLock;
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.nio.file.StandardOpenOption;
|
import java.nio.file.StandardOpenOption;
|
||||||
import java.util.Scanner;
|
import java.util.Scanner;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
@ -107,11 +107,10 @@ public class CacheManager {
|
||||||
clearDiskStore(cache);
|
clearDiskStore(cache);
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: use UTF8
|
|
||||||
if (isNewCache) {
|
if (isNewCache) {
|
||||||
// set new cache revision
|
// set new cache revision
|
||||||
channel.position(0);
|
channel.position(0);
|
||||||
channel.write(Charset.forName("UTF-8").encode(String.valueOf(applicationRevision)));
|
channel.write(UTF_8.encode(String.valueOf(applicationRevision)));
|
||||||
channel.truncate(channel.position());
|
channel.truncate(channel.position());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.filebot;
|
package net.filebot;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
import static java.nio.file.Files.*;
|
import static java.nio.file.Files.*;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -46,7 +47,7 @@ public class MetaAttributeView extends AbstractMap<String, String> {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// UserDefinedFileAttributeView
|
// UserDefinedFileAttributeView
|
||||||
this.encoding = Charset.forName("UTF-8");
|
this.encoding = UTF_8;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.filebot.cli;
|
package net.filebot.cli;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
import static java.util.Arrays.*;
|
import static java.util.Arrays.*;
|
||||||
import static java.util.Collections.*;
|
import static java.util.Collections.*;
|
||||||
import static net.filebot.Logging.*;
|
import static net.filebot.Logging.*;
|
||||||
|
@ -689,7 +690,7 @@ public class CmdlineOperations implements CmdlineInterface {
|
||||||
final SubtitleNaming naming = getSubtitleNaming(format);
|
final SubtitleNaming naming = getSubtitleNaming(format);
|
||||||
|
|
||||||
// when rewriting subtitles to target format an encoding must be defined, default to UTF-8
|
// when rewriting subtitles to target format an encoding must be defined, default to UTF-8
|
||||||
final Charset outputEncoding = (csn != null) ? Charset.forName(csn) : (output != null) ? Charset.forName("UTF-8") : null;
|
final Charset outputEncoding = csn != null ? Charset.forName(csn) : output != null ? UTF_8 : null;
|
||||||
final SubtitleFormat outputFormat = (output != null) ? getSubtitleFormatByName(output) : null;
|
final SubtitleFormat outputFormat = (output != null) ? getSubtitleFormatByName(output) : null;
|
||||||
|
|
||||||
// ignore anything that is not a video
|
// ignore anything that is not a video
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.filebot.cli;
|
package net.filebot.cli;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
import static java.util.Arrays.*;
|
import static java.util.Arrays.*;
|
||||||
import static java.util.Collections.*;
|
import static java.util.Collections.*;
|
||||||
import static net.filebot.MediaTypes.*;
|
import static net.filebot.MediaTypes.*;
|
||||||
|
@ -9,7 +10,6 @@ import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.nio.file.FileVisitResult;
|
import java.nio.file.FileVisitResult;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
|
@ -272,7 +272,7 @@ public class ScriptShellMethods {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getText(ByteBuffer self) {
|
public static String getText(ByteBuffer self) {
|
||||||
return Charset.forName("UTF-8").decode(self.duplicate()).toString();
|
return UTF_8.decode(self.duplicate()).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ByteBuffer get(URL self) throws IOException {
|
public static ByteBuffer get(URL self) throws IOException {
|
||||||
|
@ -318,7 +318,7 @@ public class ScriptShellMethods {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File saveAs(String self, File file) throws IOException {
|
public static File saveAs(String self, File file) throws IOException {
|
||||||
return saveAs(Charset.forName("UTF-8").encode(self), file);
|
return saveAs(UTF_8.encode(self), file);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static File saveAs(URL self, File file) throws IOException {
|
public static File saveAs(URL self, File file) throws IOException {
|
||||||
|
|
|
@ -12,8 +12,9 @@
|
||||||
*/
|
*/
|
||||||
package net.filebot.mac.xattr;
|
package net.filebot.mac.xattr;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -67,7 +68,7 @@ public class XAttrUtil {
|
||||||
|
|
||||||
protected static Memory encodeString(String s) {
|
protected static Memory encodeString(String s) {
|
||||||
// create NULL-terminated UTF-8 String
|
// create NULL-terminated UTF-8 String
|
||||||
byte[] bb = s.getBytes(Charset.forName("UTF-8"));
|
byte[] bb = s.getBytes(UTF_8);
|
||||||
Memory valueBuffer = new Memory(bb.length + 1);
|
Memory valueBuffer = new Memory(bb.length + 1);
|
||||||
valueBuffer.write(0, bb, 0, bb.length);
|
valueBuffer.write(0, bb, 0, bb.length);
|
||||||
valueBuffer.setByte(valueBuffer.size() - 1, (byte) 0);
|
valueBuffer.setByte(valueBuffer.size() - 1, (byte) 0);
|
||||||
|
@ -75,7 +76,7 @@ public class XAttrUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static String decodeString(ByteBuffer bb) {
|
protected static String decodeString(ByteBuffer bb) {
|
||||||
return Charset.forName("UTF-8").decode(bb).toString();
|
return UTF_8.decode(bb).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static List<String> decodeStringSequence(ByteBuffer bb) {
|
protected static List<String> decodeStringSequence(ByteBuffer bb) {
|
||||||
|
|
|
@ -22,34 +22,28 @@
|
||||||
|
|
||||||
package net.filebot.torrent;
|
package net.filebot.torrent;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.CharBuffer;
|
import java.nio.CharBuffer;
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A set of utility methods to decode a bencoded array of byte into a Map. integer are
|
* A set of utility methods to decode a bencoded array of byte into a Map. integer are represented as Long, String as byte[], dictionnaries as Map, and list as List.
|
||||||
* represented as Long, String as byte[], dictionnaries as Map, and list as List.
|
|
||||||
*
|
*
|
||||||
* @author TdC_VgA
|
* @author TdC_VgA
|
||||||
*/
|
*/
|
||||||
class BDecoder {
|
class BDecoder {
|
||||||
|
|
||||||
private static final Charset BINARY_CHARSET = Charset.forName("ISO-8859-1");
|
|
||||||
|
|
||||||
|
|
||||||
public static Map<?, ?> decode(InputStream is) throws IOException {
|
public static Map<?, ?> decode(InputStream is) throws IOException {
|
||||||
return (new BDecoder().decodeStream(is));
|
return (new BDecoder().decodeStream(is));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Map<?, ?> decodeStream(InputStream data) throws IOException {
|
public Map<?, ?> decodeStream(InputStream data) throws IOException {
|
||||||
Object res = decodeInputStream(data, 0);
|
Object res = decodeInputStream(data, 0);
|
||||||
|
|
||||||
|
@ -61,7 +55,6 @@ class BDecoder {
|
||||||
return ((Map<?, ?>) res);
|
return ((Map<?, ?>) res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private Object decodeInputStream(InputStream bais, int nesting) throws IOException {
|
private Object decodeInputStream(InputStream bais, int nesting) throws IOException {
|
||||||
if (!bais.markSupported())
|
if (!bais.markSupported())
|
||||||
throw new IOException("InputStream must support the mark() method");
|
throw new IOException("InputStream must support the mark() method");
|
||||||
|
@ -89,7 +82,7 @@ class BDecoder {
|
||||||
|
|
||||||
// add the value to the map
|
// add the value to the map
|
||||||
|
|
||||||
CharBuffer cb = BINARY_CHARSET.decode(ByteBuffer.wrap(tempByteArray));
|
CharBuffer cb = ISO_8859_1.decode(ByteBuffer.wrap(tempByteArray));
|
||||||
|
|
||||||
String key = new String(cb.array(), 0, cb.limit());
|
String key = new String(cb.array(), 0, cb.limit());
|
||||||
|
|
||||||
|
@ -156,7 +149,6 @@ class BDecoder {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private long getNumberFromStream(InputStream bais, char parseChar) throws IOException {
|
private long getNumberFromStream(InputStream bais, char parseChar) throws IOException {
|
||||||
int length = 0;
|
int length = 0;
|
||||||
|
|
||||||
|
@ -189,14 +181,13 @@ class BDecoder {
|
||||||
bais.skip(1);
|
bais.skip(1);
|
||||||
|
|
||||||
// return the value
|
// return the value
|
||||||
CharBuffer cb = BINARY_CHARSET.decode(ByteBuffer.wrap(tempArray));
|
CharBuffer cb = ISO_8859_1.decode(ByteBuffer.wrap(tempArray));
|
||||||
|
|
||||||
String str_value = new String(cb.array(), 0, cb.limit());
|
String str_value = new String(cb.array(), 0, cb.limit());
|
||||||
|
|
||||||
return Long.parseLong(str_value);
|
return Long.parseLong(str_value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private byte[] getByteArrayFromStream(InputStream bais) throws IOException {
|
private byte[] getByteArrayFromStream(InputStream bais) throws IOException {
|
||||||
int length = (int) getNumberFromStream(bais, ':');
|
int length = (int) getNumberFromStream(bais, ':');
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
package net.filebot.torrent;
|
package net.filebot.torrent;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
|
|
||||||
import java.io.BufferedInputStream;
|
import java.io.BufferedInputStream;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
@ -14,7 +14,6 @@ import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
|
||||||
public class Torrent {
|
public class Torrent {
|
||||||
|
|
||||||
private String name;
|
private String name;
|
||||||
|
@ -28,19 +27,16 @@ public class Torrent {
|
||||||
private List<Entry> files;
|
private List<Entry> files;
|
||||||
private boolean singleFileTorrent;
|
private boolean singleFileTorrent;
|
||||||
|
|
||||||
|
|
||||||
protected Torrent() {
|
protected Torrent() {
|
||||||
// used by serializer
|
// used by serializer
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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 = UTF_8;
|
||||||
encoding = decodeString(torrentMap.get("encoding"), charset);
|
encoding = decodeString(torrentMap.get("encoding"), charset);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -99,7 +95,6 @@ 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));
|
||||||
|
|
||||||
|
@ -110,7 +105,6 @@ 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;
|
||||||
|
@ -118,7 +112,6 @@ 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;
|
||||||
|
@ -126,82 +119,67 @@ 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();
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.filebot.ui.subtitle;
|
package net.filebot.ui.subtitle;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
import static net.filebot.MediaTypes.*;
|
import static net.filebot.MediaTypes.*;
|
||||||
import static net.filebot.UserFiles.*;
|
import static net.filebot.UserFiles.*;
|
||||||
import static net.filebot.subtitle.SubtitleUtilities.*;
|
import static net.filebot.subtitle.SubtitleUtilities.*;
|
||||||
|
@ -294,7 +295,7 @@ class SubtitleDownloadComponent extends JComponent {
|
||||||
// default values
|
// default values
|
||||||
SubtitleFormat selectedFormat = SubtitleFormat.SubRip;
|
SubtitleFormat selectedFormat = SubtitleFormat.SubRip;
|
||||||
long selectedTimingOffset = 0;
|
long selectedTimingOffset = 0;
|
||||||
Charset selectedEncoding = Charset.forName("UTF-8");
|
Charset selectedEncoding = UTF_8;
|
||||||
|
|
||||||
// just use default values when we can't use a JFC with accessory component (also Swing OSX LaF doesn't seem to support JFileChooser::setAccessory)
|
// just use default values when we can't use a JFC with accessory component (also Swing OSX LaF doesn't seem to support JFileChooser::setAccessory)
|
||||||
if (Settings.isMacApp()) {
|
if (Settings.isMacApp()) {
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
|
|
||||||
package net.filebot.ui.subtitle;
|
package net.filebot.ui.subtitle;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
import static java.util.Collections.*;
|
import static java.util.Collections.*;
|
||||||
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
|
@ -20,30 +19,26 @@ import javax.swing.SpinnerNumberModel;
|
||||||
import net.filebot.subtitle.SubtitleFormat;
|
import net.filebot.subtitle.SubtitleFormat;
|
||||||
import net.miginfocom.swing.MigLayout;
|
import net.miginfocom.swing.MigLayout;
|
||||||
|
|
||||||
|
|
||||||
public class SubtitleFileChooser extends JFileChooser {
|
public class SubtitleFileChooser extends JFileChooser {
|
||||||
|
|
||||||
protected final JComboBox format = new JComboBox();
|
protected final JComboBox format = new JComboBox();
|
||||||
protected final JComboBox encoding = new JComboBox();
|
protected final JComboBox encoding = new JComboBox();
|
||||||
protected final JSpinner offset = new JSpinner(new SpinnerNumberModel(0, -14400000, 14400000, 100));
|
protected final JSpinner offset = new JSpinner(new SpinnerNumberModel(0, -14400000, 14400000, 100));
|
||||||
|
|
||||||
|
|
||||||
public SubtitleFileChooser() {
|
public SubtitleFileChooser() {
|
||||||
setAccessory(createAcessory());
|
setAccessory(createAcessory());
|
||||||
setDefaultOptions();
|
setDefaultOptions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void setDefaultOptions() {
|
protected void setDefaultOptions() {
|
||||||
setFormatOptions(singleton(SubtitleFormat.SubRip));
|
setFormatOptions(singleton(SubtitleFormat.SubRip));
|
||||||
|
|
||||||
Set<Charset> encodings = new LinkedHashSet<Charset>(2);
|
Set<Charset> encodings = new LinkedHashSet<Charset>(2);
|
||||||
encodings.add(Charset.forName("UTF-8")); // UTF-8 as default charset
|
encodings.add(UTF_8); // UTF-8 as default charset
|
||||||
encodings.add(Charset.defaultCharset()); // allow default system encoding to be used as well
|
encodings.add(Charset.defaultCharset()); // allow default system encoding to be used as well
|
||||||
setEncodingOptions(encodings);
|
setEncodingOptions(encodings);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected JComponent createAcessory() {
|
protected JComponent createAcessory() {
|
||||||
JPanel acessory = new JPanel(new MigLayout("nogrid"));
|
JPanel acessory = new JPanel(new MigLayout("nogrid"));
|
||||||
|
|
||||||
|
@ -58,27 +53,22 @@ public class SubtitleFileChooser extends JFileChooser {
|
||||||
return acessory;
|
return acessory;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setEncodingOptions(Set<Charset> options) {
|
public void setEncodingOptions(Set<Charset> options) {
|
||||||
encoding.setModel(new DefaultComboBoxModel(options.toArray()));
|
encoding.setModel(new DefaultComboBoxModel(options.toArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public Charset getSelectedEncoding() {
|
public Charset getSelectedEncoding() {
|
||||||
return (Charset) encoding.getSelectedItem();
|
return (Charset) encoding.getSelectedItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void setFormatOptions(Set<SubtitleFormat> options) {
|
public void setFormatOptions(Set<SubtitleFormat> options) {
|
||||||
format.setModel(new DefaultComboBoxModel(options.toArray()));
|
format.setModel(new DefaultComboBoxModel(options.toArray()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public SubtitleFormat getSelectedFormat() {
|
public SubtitleFormat getSelectedFormat() {
|
||||||
return (SubtitleFormat) format.getSelectedItem();
|
return (SubtitleFormat) format.getSelectedItem();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public long getTimingOffset() {
|
public long getTimingOffset() {
|
||||||
return (Integer) offset.getValue();
|
return (Integer) offset.getValue();
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
package net.filebot.ui.transfer;
|
package net.filebot.ui.transfer;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
|
|
||||||
import java.awt.datatransfer.DataFlavor;
|
import java.awt.datatransfer.DataFlavor;
|
||||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||||
|
@ -10,17 +10,14 @@ import java.util.AbstractMap;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
|
|
||||||
public class TextFileTransferable extends ByteBufferTransferable {
|
public class TextFileTransferable extends ByteBufferTransferable {
|
||||||
|
|
||||||
private final String text;
|
private final String text;
|
||||||
|
|
||||||
|
|
||||||
public TextFileTransferable(String name, String text) {
|
public TextFileTransferable(String name, String text) {
|
||||||
this(name, text, Charset.forName("UTF-8"));
|
this(name, text, UTF_8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public TextFileTransferable(final String name, final String text, final Charset charset) {
|
public TextFileTransferable(final String name, final String text, final Charset charset) {
|
||||||
// lazy data map for file transfer
|
// lazy data map for file transfer
|
||||||
super(new AbstractMap<String, ByteBuffer>() {
|
super(new AbstractMap<String, ByteBuffer>() {
|
||||||
|
@ -39,7 +36,6 @@ public class TextFileTransferable extends ByteBufferTransferable {
|
||||||
this.text = text;
|
this.text = text;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
|
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException {
|
||||||
// check file flavor first, because text/uri-list is also text flavor
|
// check file flavor first, because text/uri-list is also text flavor
|
||||||
|
@ -55,15 +51,11 @@ public class TextFileTransferable extends ByteBufferTransferable {
|
||||||
throw new UnsupportedFlavorException(flavor);
|
throw new UnsupportedFlavorException(flavor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public DataFlavor[] getTransferDataFlavors() {
|
public DataFlavor[] getTransferDataFlavors() {
|
||||||
return new DataFlavor[] {
|
return new DataFlavor[] { DataFlavor.javaFileListFlavor, FileTransferable.uriListFlavor, DataFlavor.stringFlavor };
|
||||||
DataFlavor.javaFileListFlavor, FileTransferable.uriListFlavor, DataFlavor.stringFlavor
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||||
// file flavor or text flavor
|
// file flavor or text flavor
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.filebot.util;
|
package net.filebot.util;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
import static net.filebot.util.FileUtilities.*;
|
import static net.filebot.util.FileUtilities.*;
|
||||||
import static net.filebot.web.WebRequest.*;
|
import static net.filebot.web.WebRequest.*;
|
||||||
|
|
||||||
|
@ -10,7 +11,6 @@ import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
import java.nio.channels.ReadableByteChannel;
|
import java.nio.channels.ReadableByteChannel;
|
||||||
import java.nio.channels.WritableByteChannel;
|
import java.nio.channels.WritableByteChannel;
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -59,7 +59,7 @@ public class DownloadTask extends SwingWorker<ByteBuffer, Void> {
|
||||||
HttpURLConnection connection = createConnection();
|
HttpURLConnection connection = createConnection();
|
||||||
|
|
||||||
if (postParameters != null) {
|
if (postParameters != null) {
|
||||||
ByteBuffer postData = Charset.forName("UTF-8").encode(encodeParameters(postParameters, true));
|
ByteBuffer postData = UTF_8.encode(encodeParameters(postParameters, true));
|
||||||
|
|
||||||
// add content type and content length headers
|
// add content type and content length headers
|
||||||
connection.addRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
connection.addRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.filebot.util;
|
package net.filebot.util;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
import static java.util.Arrays.*;
|
import static java.util.Arrays.*;
|
||||||
import static java.util.Collections.*;
|
import static java.util.Collections.*;
|
||||||
|
|
||||||
|
@ -15,7 +16,6 @@ import java.io.Reader;
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.nio.channels.FileChannel;
|
import java.nio.channels.FileChannel;
|
||||||
import java.nio.charset.Charset;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.nio.file.AtomicMoveNotSupportedException;
|
import java.nio.file.AtomicMoveNotSupportedException;
|
||||||
import java.nio.file.FileVisitOption;
|
import java.nio.file.FileVisitOption;
|
||||||
|
@ -255,7 +255,7 @@ public final class FileUtilities {
|
||||||
}
|
}
|
||||||
|
|
||||||
// assume UTF-8 by default
|
// assume UTF-8 by default
|
||||||
return Charset.forName("UTF-8").decode(data).toString();
|
return UTF_8.decode(data).toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
package net.filebot.web;
|
package net.filebot.web;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
import static net.filebot.util.FileUtilities.*;
|
import static net.filebot.util.FileUtilities.*;
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
|
@ -284,12 +285,12 @@ public final class WebRequest {
|
||||||
|
|
||||||
// use http default encoding only for text/html
|
// use http default encoding only for text/html
|
||||||
if (contentType.equals("text/html")) {
|
if (contentType.equals("text/html")) {
|
||||||
return Charset.forName("ISO-8859-1");
|
return ISO_8859_1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// use UTF-8 if we don't know any better
|
// use UTF-8 if we don't know any better
|
||||||
return Charset.forName("UTF-8");
|
return UTF_8;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getXmlString(Document dom, boolean indent) throws TransformerException {
|
public static String getXmlString(Document dom, boolean indent) throws TransformerException {
|
||||||
|
|
|
@ -1,17 +1,14 @@
|
||||||
|
|
||||||
package net.filebot.util;
|
package net.filebot.util;
|
||||||
|
|
||||||
|
import static java.nio.charset.StandardCharsets.*;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.channels.Channels;
|
import java.nio.channels.Channels;
|
||||||
import java.nio.charset.Charset;
|
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
||||||
public class ByteBufferOutputStreamTest {
|
public class ByteBufferOutputStreamTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -22,13 +19,12 @@ public class ByteBufferOutputStreamTest {
|
||||||
buffer.write("asdf".getBytes("utf-8"));
|
buffer.write("asdf".getBytes("utf-8"));
|
||||||
|
|
||||||
// check content
|
// check content
|
||||||
assertEquals("asdf", Charset.forName("utf-8").decode(buffer.getByteBuffer()).toString());
|
assertEquals("asdf", UTF_8.decode(buffer.getByteBuffer()).toString());
|
||||||
|
|
||||||
// check capacity
|
// check capacity
|
||||||
assertEquals(4, buffer.capacity());
|
assertEquals(4, buffer.capacity());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void transferFrom() throws Exception {
|
public void transferFrom() throws Exception {
|
||||||
InputStream in = new ByteArrayInputStream("asdf".getBytes("utf-8"));
|
InputStream in = new ByteArrayInputStream("asdf".getBytes("utf-8"));
|
||||||
|
@ -41,7 +37,7 @@ public class ByteBufferOutputStreamTest {
|
||||||
assertEquals(4, n);
|
assertEquals(4, n);
|
||||||
|
|
||||||
// check content
|
// check content
|
||||||
assertEquals("asdf", Charset.forName("utf-8").decode(buffer.getByteBuffer()).toString());
|
assertEquals("asdf", UTF_8.decode(buffer.getByteBuffer()).toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue