diff --git a/source/net/sourceforge/filebot/FileBotUtil.java b/source/net/sourceforge/filebot/FileBotUtil.java
index 9209cc2d..632ceec6 100644
--- a/source/net/sourceforge/filebot/FileBotUtil.java
+++ b/source/net/sourceforge/filebot/FileBotUtil.java
@@ -28,6 +28,8 @@ public final class FileBotUtil {
public static final String INVALID_CHARACTERS = "\\/:*?\"<>|\r\n";
public static final Pattern INVALID_CHARACTERS_PATTERN = Pattern.compile(String.format("[%s]+", Pattern.quote(INVALID_CHARACTERS)));
+ public static final Pattern EMBEDDED_CHECKSUM_PATTERN = Pattern.compile("[(\\[](\\p{XDigit}{8})[\\])]");
+
/**
* Strip filename of invalid characters
diff --git a/source/net/sourceforge/filebot/ui/panel/sfv/ChecksumRow.java b/source/net/sourceforge/filebot/ui/panel/sfv/ChecksumRow.java
index 97a8a4e9..a81231d3 100644
--- a/source/net/sourceforge/filebot/ui/panel/sfv/ChecksumRow.java
+++ b/source/net/sourceforge/filebot/ui/panel/sfv/ChecksumRow.java
@@ -7,7 +7,8 @@ import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.regex.Matcher;
-import java.util.regex.Pattern;
+
+import net.sourceforge.filebot.FileBotUtil;
public class ChecksumRow {
@@ -50,7 +51,7 @@ public class ChecksumRow {
*/
private static Long getEmbeddedChecksum(String name) {
// look for a checksum pattern like [49A93C5F]
- Matcher matcher = Pattern.compile("\\[(\\p{XDigit}{8})\\]").matcher(name);
+ Matcher matcher = FileBotUtil.EMBEDDED_CHECKSUM_PATTERN.matcher(name);
if (matcher.find())
return Long.parseLong(matcher.group(1), 16);
diff --git a/source/net/sourceforge/filebot/ui/panel/sfv/HighlightPatternCellRenderer.java b/source/net/sourceforge/filebot/ui/panel/sfv/HighlightPatternCellRenderer.java
index b31400cb..f0e584d8 100644
--- a/source/net/sourceforge/filebot/ui/panel/sfv/HighlightPatternCellRenderer.java
+++ b/source/net/sourceforge/filebot/ui/panel/sfv/HighlightPatternCellRenderer.java
@@ -3,6 +3,7 @@ package net.sourceforge.filebot.ui.panel.sfv;
import java.awt.Component;
+import java.util.regex.Pattern;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;
@@ -13,12 +14,12 @@ import javax.swing.table.DefaultTableCellRenderer;
*/
class HighlightPatternCellRenderer extends DefaultTableCellRenderer {
- private final String pattern;
+ private final Pattern pattern;
private final String cssColor;
private final String cssFontSize;
- public HighlightPatternCellRenderer(String pattern, String cssColor, String cssFontSize) {
+ public HighlightPatternCellRenderer(Pattern pattern, String cssColor, String cssFontSize) {
this.pattern = pattern;
this.cssColor = cssColor;
this.cssFontSize = cssFontSize;
@@ -31,7 +32,7 @@ class HighlightPatternCellRenderer extends DefaultTableCellRenderer {
// highlight CRC32 checksum patterns by using a smaller font-size and changing the font-color to a dark green
// do not change the font-color if cell is selected, because that would look ugly (imagine green text on blue background ...)
- String htmlText = value.toString().replaceAll(pattern, "[$1]");
+ String htmlText = pattern.matcher(value.toString()).replaceAll("[$1]");
// use no-break, because we really don't want line-wrapping in our table cells
setText("" + htmlText + "");
diff --git a/source/net/sourceforge/filebot/ui/panel/sfv/SfvTable.java b/source/net/sourceforge/filebot/ui/panel/sfv/SfvTable.java
index dc51e1c7..b86ea04a 100644
--- a/source/net/sourceforge/filebot/ui/panel/sfv/SfvTable.java
+++ b/source/net/sourceforge/filebot/ui/panel/sfv/SfvTable.java
@@ -13,6 +13,7 @@ import javax.swing.plaf.basic.BasicTableUI;
import javax.swing.table.TableColumn;
import javax.swing.table.TableModel;
+import net.sourceforge.filebot.FileBotUtil;
import net.sourceforge.filebot.ui.panel.sfv.ChecksumTableModel.ChecksumTableModelEvent;
import net.sourceforge.filebot.ui.transfer.DefaultTransferHandler;
@@ -45,7 +46,7 @@ class SfvTable extends JTable {
setUI(new DragDropRowTableUI());
// highlight CRC32 patterns in filenames in green and with smaller font-size
- setDefaultRenderer(String.class, new HighlightPatternCellRenderer("\\[(\\p{XDigit}{8})\\]", "#009900", "smaller"));
+ setDefaultRenderer(String.class, new HighlightPatternCellRenderer(FileBotUtil.EMBEDDED_CHECKSUM_PATTERN, "#009900", "smaller"));
setDefaultRenderer(ChecksumRow.State.class, new StateIconTableCellRenderer());
setDefaultRenderer(Checksum.class, new ChecksumTableCellRenderer());
}
diff --git a/source/net/sourceforge/filebot/ui/transfer/LazyTextFileTransferable.java b/source/net/sourceforge/filebot/ui/transfer/LazyTextFileTransferable.java
index 9b2294b7..4e56aff7 100644
--- a/source/net/sourceforge/filebot/ui/transfer/LazyTextFileTransferable.java
+++ b/source/net/sourceforge/filebot/ui/transfer/LazyTextFileTransferable.java
@@ -55,12 +55,16 @@ public class LazyTextFileTransferable implements Transferable {
String validFileName = FileBotUtil.validateFileName(defaultFileName);
// create new temporary file in TEMP/APP_NAME [UUID]/dnd
- File temporaryFile = TemporaryFolder.getFolder(FileBotUtil.getApplicationName().toLowerCase()).subFolder("dnd").createFile(validFileName);
+ File temporaryFile = TemporaryFolder.getFolder(FileBotUtil.getApplicationName()).subFolder("dnd").createFile(validFileName);
// write text to file
FileChannel fileChannel = new FileOutputStream(temporaryFile).getChannel();
- fileChannel.write(Charset.forName("UTF-8").encode(text));
- fileChannel.close();
+
+ try {
+ fileChannel.write(Charset.forName("UTF-8").encode(text));
+ } finally {
+ fileChannel.close();
+ }
return new FileTransferable(temporaryFile);
}
diff --git a/source/net/sourceforge/tuned/TemporaryFolder.java b/source/net/sourceforge/tuned/TemporaryFolder.java
index d504ad25..9bce8809 100644
--- a/source/net/sourceforge/tuned/TemporaryFolder.java
+++ b/source/net/sourceforge/tuned/TemporaryFolder.java
@@ -20,20 +20,23 @@ public final class TemporaryFolder {
/**
* Get a {@link TemporaryFolder} instance for a given name. The actual directory will be
- * created lazily (e.g. when a file is created). The directories name will start with the
- * given name and contain a unique id, so multiple application instances may run at the
- * same time without the risk of interference.
+ * created lazily (e.g. when a file is created). The name of the directory will start with
+ * the given name (lower-case) and contain a unique id, so multiple application instances
+ * may run at the same time without the risk of interference.
*
* @param name case-insensitive name of a temporary folder (e.g. application name)
* @return temporary folder for this name
*/
public static TemporaryFolder getFolder(String name) {
+ // make name case-insensitive
+ name = name.toLowerCase();
+
synchronized (folders) {
- TemporaryFolder folder = folders.get(name.toLowerCase());
+ TemporaryFolder folder = folders.get(name);
if (folder == null) {
folder = new TemporaryFolder(new File(tmpdir, String.format("%s [%s]", name, UUID.randomUUID())));
- folders.put(name.toLowerCase(), folder);
+ folders.put(name, folder);
}
return folder;