forked from External/mage
* UI: added drag & drop text to deck editor (like drag & drop deck file);
This commit is contained in:
parent
5eecfb2a86
commit
b6f075c505
4 changed files with 69 additions and 44 deletions
|
|
@ -1,12 +1,19 @@
|
|||
|
||||
package mage.util;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author LevelX2
|
||||
*/
|
||||
public final class DeckUtil {
|
||||
|
||||
private static final Logger logger = Logger.getLogger(DeckUtil.class);
|
||||
|
||||
public static long fixedHash(String string) {
|
||||
long h = 1125899906842597L; // prime
|
||||
int len = string.length();
|
||||
|
|
@ -16,4 +23,23 @@ public final class DeckUtil {
|
|||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
public static String writeTextToTempFile(String text) {
|
||||
return writeTextToTempFile("cbimportdeck", ".txt", text);
|
||||
}
|
||||
|
||||
public static String writeTextToTempFile(String filePrefix, String fileSuffix, String text) {
|
||||
BufferedWriter bw = null;
|
||||
try {
|
||||
File temp = File.createTempFile(filePrefix, fileSuffix);
|
||||
bw = new BufferedWriter(new FileWriter(temp));
|
||||
bw.write(text);
|
||||
return temp.getPath();
|
||||
} catch (IOException e) {
|
||||
logger.error("Can't write deck file to temp file", e);
|
||||
} finally {
|
||||
StreamUtils.closeQuietly(bw);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue