Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

flag/deprecate unused/misnamed code

  • Loading branch information...
commit 7b049417d74907ea6b67324df3fe6f9fb4d4d008 1 parent 450c2d9
@chocolateboy chocolateboy authored
View
2  src/main/external-resources/PMS.conf
@@ -265,7 +265,7 @@ alternate_thumb_folder =
# GUI Option: Browse compressed archives (toggle)
# Should the system browse compressed files looking for media? Files are
# extracted only when selected for viewing.
-# Archives supported include zip, rar, cbr and possibly others.
+# Supported formats: cbr, cbz, rar and zip.
# Default: false.
enable_archive_browsing =
View
2  src/main/java/net/pms/dlna/CueFolder.java
@@ -27,7 +27,7 @@ public File getPlaylistfile() {
public CueFolder(File f) {
playlistfile = f;
- setLastmodified(playlistfile.lastModified());
+ setLastModified(playlistfile.lastModified());
}
@Override
View
18 src/main/java/net/pms/dlna/DLNAMediaDatabase.java
@@ -578,8 +578,8 @@ public void cleanup() {
while (rs.next()) {
String filename = rs.getString("FILENAME");
long modified = rs.getTimestamp("MODIFIED").getTime();
- File entry = new File(filename);
- if (!entry.exists() || entry.lastModified() != modified) {
+ File file = new File(filename);
+ if (!file.exists() || file.lastModified() != modified) {
rs.deleteRow();
}
i++;
@@ -611,9 +611,9 @@ public void cleanup() {
while (rs.next()) {
String filename = rs.getString("FILENAME");
long modified = rs.getTimestamp("MODIFIED").getTime();
- File entry = new File(filename);
- if (entry.exists() && entry.lastModified() == modified) {
- list.add(entry);
+ File file = new File(filename);
+ if (file.exists() && file.lastModified() == modified) {
+ list.add(file);
}
}
} catch (SQLException se) {
@@ -686,15 +686,15 @@ public void run() {
public void compact() {
logger.info("Compacting database...");
PMS.get().getFrame().setStatusLine(Messages.getString("DLNAMediaDatabase.3"));
- String file = "database/backup.sql";
+ String filename = "database/backup.sql";
try {
- Script.execute(url, "sa", "", file);
+ Script.execute(url, "sa", "", filename);
DeleteDbFiles.execute(dir, "medias", true); // TODO: rename "medias" -> "cache"
- RunScript.execute(url, "sa", "", file, null, false);
+ RunScript.execute(url, "sa", "", filename, null, false);
} catch (Exception s) {
logger.error("Error in compacting database: ", s);
} finally {
- File testsql = new File(file);
+ File testsql = new File(filename);
if (testsql.exists() && !testsql.delete()) {
testsql.deleteOnExit();
}
View
46 src/main/java/net/pms/dlna/DLNAResource.java
@@ -131,7 +131,7 @@
* @deprecated Use standard getter and setter to access this field.
*/
@Deprecated
- protected long lastmodified;
+ protected long lastmodified; // TODO make private and rename lastmodified -> lastModified
/**
* Represents the transformation to be used to the file. If null, then
@@ -1276,8 +1276,8 @@ public final String toString(RendererConfiguration mediaRenderer) {
closeTag(sb, "res");
}
- if (getLastmodified() > 0) {
- addXMLTagAndAttribute(sb, "dc:date", SDF_DATE.format(new Date(getLastmodified())));
+ if (getLastModified() > 0) {
+ addXMLTagAndAttribute(sb, "dc:date", SDF_DATE.format(new Date(getLastModified())));
}
String uclass = null;
@@ -1459,7 +1459,7 @@ public InputStream getInputStream(Range range, RendererConfiguration mediarender
int rewind_secs = mediarenderer.getByteToTimeseekRewindSeconds();
timeRange.rewindStart(rewind_secs);
- //shagrath:
+ // shagrath:
timeseek_auto = true;
}
}
@@ -1484,13 +1484,13 @@ public InputStream getInputStream(Range range, RendererConfiguration mediarender
if (getFormat() != null && getFormat().isImage() && getMedia() != null && getMedia().getOrientation() > 1 && mediarenderer.isAutoRotateBasedOnExif()) {
// seems it's a jpeg file with an orientation setting to take care of
fis = ImagesUtil.getAutoRotateInputStreamImage(getInputStream(), getMedia().getOrientation());
- if (fis == null) // error, let's return the original one
- {
+ if (fis == null) { // error, let's return the original one
fis = getInputStream();
}
} else {
fis = getInputStream();
}
+
if (fis != null) {
if (low > 0) {
fis.skip(low);
@@ -1819,22 +1819,48 @@ protected void setMediaSubtitle(DLNAMediaSubtitle mediaSubtitle) {
}
/**
+ * @deprecated Use {@link #getLastModified()} instead.
+ *
* Returns the timestamp at which this resource was last modified.
*
* @return The timestamp.
*/
+ @Deprecated
public long getLastmodified() {
- return lastmodified;
+ return getLastModified();
+ }
+
+ /**
+ * Returns the timestamp at which this resource was last modified.
+ *
+ * @return The timestamp.
+ * @since 1.71.0
+ */
+ public long getLastModified() {
+ return lastmodified; // TODO rename lastmodified -> lastModified
}
/**
+ * @deprecated Use {@link #setLastModified()} instead.
+ *
* Sets the timestamp at which this resource was last modified.
*
- * @param lastmodified The timestamp to set.
+ * @param lastModified The timestamp to set.
* @since 1.50
*/
- protected void setLastmodified(long lastmodified) {
- this.lastmodified = lastmodified;
+ @Deprecated
+ protected void setLastmodified(long lastModified) {
+ setLastModified(lastModified);
+ }
+
+ /**
+ * Sets the timestamp at which this resource was last modified.
+ *
+ * @param lastModified The timestamp to set.
+ * @since 1.71.0
+ */
+ protected void setLastModified(long lastModified) {
+ this.lastmodified = lastModified; // TODO rename lastmodified -> lastModified
}
/**
View
2  src/main/java/net/pms/dlna/DVDISOFile.java
@@ -86,7 +86,7 @@ public void run() {
public DVDISOFile(File f) {
super(PREFIX + (f.isFile() ? f.getName() : "VIDEO_TS"), null);
this.f = f;
- setLastmodified(f.lastModified());
+ setLastModified(f.lastModified());
}
@Override
View
2  src/main/java/net/pms/dlna/DVDISOTitle.java
@@ -223,7 +223,7 @@ public long getLength() {
public DVDISOTitle(File f, int title) {
this.f = f;
this.title = title;
- setLastmodified(f.lastModified());
+ setLastModified(f.lastModified());
}
@Override
View
6 src/main/java/net/pms/dlna/Feed.java
@@ -143,7 +143,7 @@ public void parse() throws Exception {
manageItem();
}
}
- setLastmodified(System.currentTimeMillis());
+ setLastModified(System.currentTimeMillis());
}
@SuppressWarnings("unchecked")
@@ -185,6 +185,8 @@ public long length() {
return 0;
}
+ // XXX unused
+ @Deprecated
public long lastModified() {
return 0;
}
@@ -206,7 +208,7 @@ protected void manageItem() {
@Override
public boolean isRefreshNeeded() {
- return (System.currentTimeMillis() - getLastmodified() > 3600000);
+ return (System.currentTimeMillis() - getLastModified() > 3600000);
}
@Override
View
2  src/main/java/net/pms/dlna/FeedItem.java
@@ -76,6 +76,8 @@ public long length() {
return length;
}
+ // XXX unused
+ @Deprecated
public long lastModified() {
return 0;
}
View
14 src/main/java/net/pms/dlna/MapFile.java
@@ -66,12 +66,12 @@
public MapFile() {
setConf(new MapFileConfiguration());
- setLastmodified(0);
+ setLastModified(0);
}
public MapFile(MapFileConfiguration conf) {
setConf(conf);
- setLastmodified(0);
+ setLastModified(0);
}
private boolean isFileRelevant(File f) {
@@ -250,13 +250,15 @@ public int compare(File f1, File f2) {
@Override
public boolean isRefreshNeeded() {
- long lastModif = 0;
+ long modified = 0;
+
for (File f : this.getConf().getFiles()) {
if (f != null) {
- lastModif = Math.max(lastModif, f.lastModified());
+ modified = Math.max(modified, f.lastModified());
}
}
- return getLastRefreshTime() < lastModif;
+
+ return getLastRefreshTime() < modified;
}
@Override
@@ -319,7 +321,7 @@ private boolean foundInList(List<File> files, DLNAResource d) {
}
private boolean isSameLastModified(File f, DLNAResource d) {
- return d.getLastmodified() == f.lastModified();
+ return d.getLastModified() == f.lastModified();
}
private boolean isRealFolder(DLNAResource d) {
View
2  src/main/java/net/pms/dlna/PlaylistFolder.java
@@ -19,7 +19,7 @@ public File getPlaylistfile() {
public PlaylistFolder(File f) {
playlistfile = f;
- setLastmodified(playlistfile.lastModified());
+ setLastModified(playlistfile.lastModified());
}
@Override
View
33 src/main/java/net/pms/dlna/RarredEntry.java
@@ -20,8 +20,10 @@
import com.github.junrar.Archive;
import com.github.junrar.rarfile.FileHeader;
+
import net.pms.formats.Format;
import net.pms.util.FileUtil;
+
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -33,23 +35,23 @@
public class RarredEntry extends DLNAResource implements IPushOutput {
private static final Logger logger = LoggerFactory.getLogger(RarredEntry.class);
private String name;
- private File pere;
- private String fileheadername;
+ private File file;
+ private String fileHeaderName;
private long length;
@Override
protected String getThumbnailURL() {
- if (getType() == Format.IMAGE || getType() == Format.AUDIO) // no thumbnail support for now for real based disk images
- {
+ if (getType() == Format.IMAGE || getType() == Format.AUDIO) { // no thumbnail support for now for rarred videos
return null;
}
+
return super.getThumbnailURL();
}
- public RarredEntry(String name, File pere, String fileheadername, long length) {
- this.fileheadername = fileheadername;
+ public RarredEntry(String name, File file, String fileHeaderName, long length) {
+ this.fileHeaderName = fileHeaderName;
this.name = name;
- this.pere = pere;
+ this.file = file;
this.length = length;
}
@@ -65,6 +67,7 @@ public long length() {
if (getPlayer() != null && getPlayer().type() != Format.IMAGE) {
return DLNAMediaInfo.TRANS_SIZE;
}
+
return length;
}
@@ -72,19 +75,21 @@ public boolean isFolder() {
return false;
}
+ // XXX unused
+ @Deprecated
public long lastModified() {
return 0;
}
@Override
public String getSystemName() {
- return FileUtil.getFileNameWithoutExtension(pere.getAbsolutePath()) + "." + FileUtil.getExtension(name);
+ return FileUtil.getFileNameWithoutExtension(file.getAbsolutePath()) + "." + FileUtil.getExtension(name);
}
@Override
public boolean isValid() {
checktype();
- setSrtFile(FileUtil.doesSubtitlesExists(pere, null));
+ setSrtFile(FileUtil.doesSubtitlesExists(file, null));
return getFormat() != null;
}
@@ -100,10 +105,10 @@ public void push(final OutputStream out) throws IOException {
public void run() {
Archive rarFile = null;
try {
- rarFile = new Archive(pere);
+ rarFile = new Archive(file);
FileHeader header = null;
for (FileHeader fh : rarFile.getFileHeaders()) {
- if (fh.getFileNameString().equals(fileheadername)) {
+ if (fh.getFileNameString().equals(fileHeaderName)) {
header = fh;
break;
}
@@ -124,6 +129,7 @@ public void run() {
}
}
};
+
new Thread(r, "Rar Extractor").start();
}
@@ -132,12 +138,16 @@ public void resolve() {
if (getFormat() == null || !getFormat().isVideo()) {
return;
}
+
boolean found = false;
+
if (!found) {
if (getMedia() == null) {
setMedia(new DLNAMediaInfo());
}
+
found = !getMedia().isMediaparsed() && !getMedia().isParsing();
+
if (getFormat() != null) {
InputFile input = new InputFile();
input.setPush(this);
@@ -145,6 +155,7 @@ public void resolve() {
getFormat().parse(getMedia(), input, getType());
}
}
+
super.resolve();
}
View
11 src/main/java/net/pms/dlna/RarredFile.java
@@ -37,14 +37,17 @@
public RarredFile(File f) {
this.f = f;
- setLastmodified(f.lastModified());
+ setLastModified(f.lastModified());
+
try {
rarFile = new Archive(f);
List<FileHeader> headers = rarFile.getFileHeaders();
+
for (FileHeader fh : headers) {
- //if (fh.getFullUnpackSize() < MAX_ARCHIVE_ENTRY_SIZE && fh.getFullPackSize() < MAX_ARCHIVE_ENTRY_SIZE)
+ // if (fh.getFullUnpackSize() < MAX_ARCHIVE_ENTRY_SIZE && fh.getFullPackSize() < MAX_ARCHIVE_ENTRY_SIZE)
addChild(new RarredEntry(fh.getFileNameString(), f, fh.getFileNameString(), fh.getFullUnpackSize()));
}
+
rarFile.close();
} catch (RarException e) {
logger.error(null, e);
@@ -69,6 +72,8 @@ public boolean isFolder() {
return true;
}
+ // XXX unused
+ @Deprecated
public long lastModified() {
return 0;
}
@@ -81,11 +86,13 @@ public String getSystemName() {
@Override
public boolean isValid() {
boolean t = false;
+
try {
t = f.exists() && !rarFile.isEncrypted();
} catch (Throwable th) {
logger.debug("Caught exception", th);
}
+
return t;
}
}
View
4 src/main/java/net/pms/dlna/RealFile.java
@@ -35,13 +35,13 @@
public RealFile(File file) {
getConf().getFiles().add(file);
- setLastmodified(file.lastModified());
+ setLastModified(file.lastModified());
}
public RealFile(File file, String name) {
getConf().getFiles().add(file);
getConf().setName(name);
- setLastmodified(file.lastModified());
+ setLastModified(file.lastModified());
}
@Override
View
2  src/main/java/net/pms/dlna/WebStream.java
@@ -104,6 +104,8 @@ public boolean isFolder() {
return false;
}
+ // XXX unused
+ @Deprecated
public long lastModified() {
return 0;
}
View
44 src/main/java/net/pms/dlna/ZippedEntry.java
@@ -31,8 +31,8 @@
import java.util.zip.ZipFile;
public class ZippedEntry extends DLNAResource implements IPushOutput {
- private static final Logger logger = LoggerFactory.getLogger(ZippedEntry.class);
- private File z;
+ private static final Logger LOGGER = LoggerFactory.getLogger(ZippedEntry.class);
+ private File file;
private String zeName;
private long length;
private ZipFile zipFile;
@@ -40,15 +40,16 @@
@Override
protected String getThumbnailURL() {
if (getType() == Format.IMAGE || getType() == Format.AUDIO) {
- // no thumbnail support for now for real based disk images
+ // no thumbnail support for now for zipped videos
return null;
}
+
return super.getThumbnailURL();
}
- public ZippedEntry(File z, String zeName, long length) {
+ public ZippedEntry(File file, String zeName, long length) {
this.zeName = zeName;
- this.z = z;
+ this.file = file;
this.length = length;
}
@@ -64,6 +65,7 @@ public long length() {
if (getPlayer() != null && getPlayer().type() != Format.IMAGE) {
return DLNAMediaInfo.TRANS_SIZE;
}
+
return length;
}
@@ -71,19 +73,21 @@ public boolean isFolder() {
return false;
}
+ // XXX unused
+ @Deprecated
public long lastModified() {
return 0;
}
@Override
public String getSystemName() {
- return FileUtil.getFileNameWithoutExtension(z.getAbsolutePath()) + "." + FileUtil.getExtension(zeName);
+ return FileUtil.getFileNameWithoutExtension(file.getAbsolutePath()) + "." + FileUtil.getExtension(zeName);
}
@Override
public boolean isValid() {
checktype();
- setSrtFile(FileUtil.doesSubtitlesExists(z, null));
+ setSrtFile(FileUtil.doesSubtitlesExists(file, null));
return getFormat() != null;
}
@@ -95,29 +99,38 @@ public boolean isUnderlyingSeekSupported() {
@Override
public void push(final OutputStream out) throws IOException {
Runnable r = new Runnable() {
+ InputStream in = null;
+
public void run() {
try {
- zipFile = new ZipFile(z);
- ZipEntry ze = zipFile.getEntry(zeName);
- InputStream in = zipFile.getInputStream(ze);
int n = -1;
- byte data[] = new byte[65536];
+ byte[] data = new byte[65536];
+ zipFile = new ZipFile(file);
+ ZipEntry ze = zipFile.getEntry(zeName);
+ in = zipFile.getInputStream(ze);
+
while ((n = in.read(data)) > -1) {
out.write(data, 0, n);
}
+
in.close();
+ in = null;
} catch (Exception e) {
- logger.debug("Unpack error, maybe it's normal, as backend can be terminated: " + e.getMessage());
+ LOGGER.error("Unpack error. Possibly harmless.", e);
} finally {
try {
+ if (in != null) {
+ in.close();
+ }
zipFile.close();
out.close();
} catch (IOException e) {
- logger.debug("Caught exception", e);
+ LOGGER.debug("Caught exception", e);
}
}
}
};
+
new Thread(r, "Zip Extractor").start();
}
@@ -126,12 +139,16 @@ public void resolve() {
if (getFormat() == null || !getFormat().isVideo()) {
return;
}
+
boolean found = false;
+
if (!found) {
if (getMedia() == null) {
setMedia(new DLNAMediaInfo());
}
+
found = !getMedia().isMediaparsed() && !getMedia().isParsing();
+
if (getFormat() != null) {
InputFile input = new InputFile();
input.setPush(this);
@@ -139,6 +156,7 @@ public void resolve() {
getFormat().parse(getMedia(), input, getType());
}
}
+
super.resolve();
}
View
36 src/main/java/net/pms/dlna/ZippedFile.java
@@ -30,68 +30,74 @@
import java.util.zip.ZipInputStream;
public class ZippedFile extends DLNAResource {
- private static final Logger logger = LoggerFactory.getLogger(ZippedFile.class);
- private File z;
+ private static final Logger LOGGER = LoggerFactory.getLogger(ZippedFile.class);
+ private File file;
private ZipFile zip;
- public ZippedFile(File z) {
- this.z = z;
- setLastmodified(z.lastModified());
+ public ZippedFile(File file) {
+ this.file = file;
+ setLastModified(file.lastModified());
+
try {
- zip = new ZipFile(z);
+ zip = new ZipFile(file);
Enumeration<? extends ZipEntry> enm = zip.entries();
+
while (enm.hasMoreElements()) {
ZipEntry ze = enm.nextElement();
- addChild(new ZippedEntry(z, ze.getName(), ze.getSize()));
+ addChild(new ZippedEntry(file, ze.getName(), ze.getSize()));
}
+
zip.close();
} catch (ZipException e) {
- logger.error(null, e);
+ LOGGER.error("Error reading zip file", e);
} catch (IOException e) {
- logger.error(null, e);
+ LOGGER.error("Error reading zip file", e);
}
}
@Override
protected String getThumbnailURL() {
if (getType() == Format.IMAGE) {
- // no thumbnail support for now for real based disk images
+ // no thumbnail support for now for zip files
return null;
}
+
return super.getThumbnailURL();
}
public InputStream getInputStream() {
try {
- return new ZipInputStream(new FileInputStream(z));
+ return new ZipInputStream(new FileInputStream(file));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
}
public String getName() {
- return z.getName();
+ return file.getName();
}
public long length() {
- return z.length();
+ return file.length();
}
public boolean isFolder() {
return true;
}
+ // XXX unused
+ @Deprecated
public long lastModified() {
return 0;
}
@Override
public String getSystemName() {
- return z.getAbsolutePath();
+ return file.getAbsolutePath();
}
@Override
public boolean isValid() {
- return z.exists();
+ return file.exists();
}
}
View
2  src/main/java/net/pms/dlna/virtual/MediaLibraryFolder.java
@@ -139,7 +139,7 @@ public void doRefreshChildren() {
removedFiles.add(d);
}
String name = d.getName();
- long lm = d.getLastmodified();
+ long lm = d.getLastModified();
boolean video_ts_hack = (d instanceof DVDISOFile) && d.getName().startsWith(DVDISOFile.PREFIX) && d.getName().substring(DVDISOFile.PREFIX.length()).equals(f.getName());
if ((f.getName().equals(name) || video_ts_hack) && f.lastModified() == lm) {
removedFiles.remove(d);
View
2  src/main/java/net/pms/dlna/virtual/VirtualFolder.java
@@ -88,6 +88,8 @@ public long length() {
* TODO: (botijo) When is this used then? Is this a prototype?
* @return Zero
*/
+ // XXX unused
+ @Deprecated
public long lastModified() {
return 0;
}
View
2  src/main/java/net/pms/dlna/virtual/VirtualVideoAction.java
@@ -146,6 +146,8 @@ public long length() {
return -1; //DLNAMediaInfo.TRANS_SIZE;
}
+ // XXX unused
+ @Deprecated
public long lastModified() {
return 0;
}
View
28 src/main/java/net/pms/util/FileUtil.java
@@ -19,6 +19,10 @@
public class FileUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(FileUtil.class);
+ // FIXME why isn't this private?
+ @Deprecated
+ static Map<File, File[]> cache;
+
public static File isFileExists(String f, String ext) {
return isFileExists(new File(f), ext);
}
@@ -72,13 +76,18 @@ public static File isFileExists(File f, String ext) {
return null;
}
+ // FIXME needs to be renamed e.g. doSubtitlesExist or doesSubtitleExist
+ @Deprecated
public static boolean doesSubtitlesExists(File file, DLNAMediaInfo media) {
return doesSubtitlesExists(file, media, true);
}
+ // FIXME needs to be renamed e.g. doSubtitlesExist or doesSubtitleExist
+ @Deprecated
public static boolean doesSubtitlesExists(File file, DLNAMediaInfo media, boolean usecache) {
boolean found = browseFolderForSubtitles(file.getParentFile(), file, media, usecache);
String alternate = PMS.getConfiguration().getAlternateSubsFolder();
+
if (isNotBlank(alternate)) { // https://code.google.com/p/ps3mediaserver/issues/detail?id=737#c5
File subFolder = new File(alternate);
if (!subFolder.isAbsolute()) {
@@ -89,22 +98,25 @@ public static boolean doesSubtitlesExists(File file, DLNAMediaInfo media, boolea
LOGGER.debug("Caught exception", e);
}
}
+
if (subFolder.exists()) {
found = found || browseFolderForSubtitles(subFolder, file, media, usecache);
}
}
+
return found;
}
- static Map<File, File[]> cache;
private synchronized static boolean browseFolderForSubtitles(File subFolder, File file, DLNAMediaInfo media, boolean usecache) {
boolean found = false;
if (!usecache) {
cache = null;
}
+
if (cache == null) {
cache = new HashMap<File, File[]>();
}
+
File allSubs[] = cache.get(subFolder);
if (allSubs == null) {
allSubs = subFolder.listFiles();
@@ -112,6 +124,7 @@ private synchronized static boolean browseFolderForSubtitles(File subFolder, Fil
cache.put(subFolder, allSubs);
}
}
+
String fileName = getFileNameWithoutExtension(file.getName()).toLowerCase();
if (allSubs != null) {
for (File f : allSubs) {
@@ -122,10 +135,10 @@ private synchronized static boolean browseFolderForSubtitles(File subFolder, Fil
int a = fileName.length();
int b = fName.length() - ext.length() - 1;
String code = "";
- if (a <= b) // handling case with several dots: <video>..<extension>
- {
+ if (a <= b) { // handling case with several dots: <video>..<extension>
code = fName.substring(a, b);
}
+
if (code.startsWith(".")) {
code = code.substring(1);
}
@@ -148,6 +161,7 @@ private synchronized static boolean browseFolderForSubtitles(File subFolder, Fil
}
}
}
+
if (!exists) {
DLNAMediaSubtitle sub = new DLNAMediaSubtitle();
sub.setId(100 + (media == null ? 0 : media.getSubtitleTracksList().size())); // fake id, not used
@@ -169,11 +183,13 @@ private synchronized static boolean browseFolderForSubtitles(File subFolder, Fil
sub.setLang(code);
sub.setType(SubtitleType.valueOfFileExtension(ext));
}
+
try {
sub.setExternalFile(f);
} catch (FileNotFoundException ex) {
LOGGER.warn("Exception during external subtitles scan.", ex);
}
+
found = true;
if (media != null) {
media.getSubtitleTracksList().add(sub);
@@ -184,10 +200,10 @@ private synchronized static boolean browseFolderForSubtitles(File subFolder, Fil
}
}
}
+
return found;
}
-
/**
* Detects charset/encoding for given file. Not 100% accurate for
* non-Unicode files.
@@ -205,6 +221,7 @@ public static String getFileCharset(File file) throws IOException {
while ((numberOfBytesRead = bufferedInputStream.read(buf)) > 0 && !universalDetector.isDone()) {
universalDetector.handleData(buf, 0, numberOfBytesRead);
}
+
universalDetector.dataEnd();
String encoding = universalDetector.getDetectedCharset();
@@ -213,6 +230,7 @@ public static String getFileCharset(File file) throws IOException {
} else {
LOGGER.debug("No encoding detected for {}.", file.getAbsolutePath());
}
+
universalDetector.reset();
return encoding;
@@ -276,6 +294,7 @@ public static void convertFileFromUtf16ToUtf8(File inputFile, File outputFile) t
if (inputFile == null || !inputFile.canRead()) {
throw new FileNotFoundException("Can't read inputFile.");
}
+
try {
charset = getFileCharset(inputFile);
} catch (IOException ex) {
@@ -296,6 +315,7 @@ public static void convertFileFromUtf16ToUtf8(File inputFile, File outputFile) t
LOGGER.warn("Unsupported exception.", ex);
throw ex;
}
+
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(outputFile), "UTF-8"));
int c;
while ((c = reader.read()) != -1) {
Please sign in to comment.
Something went wrong with that request. Please try again.