case VERSION:
System.out
.println(String.format("Fanfix version %s"
- + "\nhttps://github.com/nikiroo/fanfix/"
- + "\n\tWritten by Nikiroo",
+ + "%nhttps://github.com/nikiroo/fanfix/"
+ + "%n\tWritten by Nikiroo",
Version.getCurrentVersion()));
updates.ok(); // we consider it read
break;
@Override
public int compareTo(MetaData o) {
- String oUuid = o == null ? null : o.getUuid();
- return getUuid().compareTo(oUuid);
+ if (o == null) {
+ return 1;
+ }
+
+ String uuid = getUuid();
+ String oUuid = o.getUuid();
+
+ if (uuid == null) {
+ uuid = "";
+ }
+
+ if (oUuid == null) {
+ oUuid = "";
+ }
+
+ return uuid.compareTo(oUuid);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (!(obj instanceof MetaData)) {
+ return false;
+ }
+
+ return compareTo((MetaData) obj) == 0;
+ }
+
+ @Override
+ public int hashCode() {
+ String uuid = getUuid();
+ if (uuid == null) {
+ uuid = "" + title + author + source;
+ }
+
+ return uuid.hashCode();
}
@Override
title = meta.getTitle();
}
- String tags = "";
+ StringBuilder tags = new StringBuilder();
if (meta != null && meta.getTags() != null) {
for (String tag : meta.getTags()) {
- if (!tags.isEmpty()) {
- tags += ", ";
+ if (tags.length() > 0) {
+ tags.append(", ");
}
- tags += tag;
+ tags.append(tag);
}
}
cover = size + cover;
}
+
return String.format(
"Title: [%s]\nAuthor: [%s]\nDate: [%s]\nTags: [%s]\n"
+ "Resume: [%s]\nCover: [%s]", title, meta == null ? ""
: meta.getAuthor(), meta == null ? "" : meta.getDate(),
- tags, resume, cover);
+ tags.toString(), resume, cover);
}
@Override
}
@Override
- protected void invalidateInfo(String luid) {
+ protected synchronized void invalidateInfo(String luid) {
stories = null;
sourceCovers = new HashMap<String, Image>();
}
public static void writeInfo(File targetDir, String targetName,
MetaData meta) throws IOException {
File info = new File(targetDir, targetName + ".info");
- BufferedWriter infoWriter = new BufferedWriter(new OutputStreamWriter(
- new FileOutputStream(info), "UTF-8"));
- if (meta != null) {
- try {
+ BufferedWriter infoWriter = null;
+ try {
+ infoWriter = new BufferedWriter(new OutputStreamWriter(
+ new FileOutputStream(info), "UTF-8"));
+
+ if (meta != null) {
String tags = "";
if (meta.getTags() != null) {
for (String tag : meta.getTags()) {
writeMeta(infoWriter, "CREATION_DATE", meta.getCreationDate());
writeMeta(infoWriter, "FAKE_COVER",
Boolean.toString(meta.isFakeCover()));
- } finally {
+ }
+ } finally {
+ if (infoWriter != null) {
infoWriter.close();
}
}
}
@Override
- public MetaData getMeta() {
+ public synchronized MetaData getMeta() {
return meta;
}
tmpCache.delete();
tmpCache.mkdir();
- FileOutputStream out = new FileOutputStream(new File(tmpConfig,
- "config.properties"));
- Properties props = new Properties();
- props.setProperty("CACHE_DIR", tmpCache.getAbsolutePath());
- props.store(out, null);
- out.close();
+ FileOutputStream out = null;
+ try {
+ out = new FileOutputStream(new File(tmpConfig, "config.properties"));
+ Properties props = new Properties();
+ props.setProperty("CACHE_DIR", tmpCache.getAbsolutePath());
+ props.store(out, null);
+ } finally {
+ if (out != null) {
+ out.close();
+ }
+ }
ConfigBundle config = new ConfigBundle();
Bundles.setDirectory(tmpConfig.getAbsolutePath());