+ public synchronized Image getCustomAuthorCover(String author) {
+ if (authorCovers == null) {
+ authorCovers = new HashMap<String, Image>();
+ }
+
+ Image img = authorCovers.get(author);
+ if (img != null) {
+ return img;
+ }
+
+ File cover = getAuthorCoverFile(author);
+ if (cover.exists()) {
+ InputStream in;
+ try {
+ in = new FileInputStream(cover);
+ try {
+ authorCovers.put(author, new Image(in));
+ } finally {
+ in.close();
+ }
+ } catch (FileNotFoundException e) {
+ e.printStackTrace();
+ } catch (IOException e) {
+ Instance.getInstance().getTraceHandler()
+ .error(new IOException("Cannot load the existing custom author cover: " + cover, e));
+ }
+ }
+
+ return authorCovers.get(author);
+ }
+
+ @Override
+ public void setSourceCover(String source, String luid) throws IOException {
+ setSourceCover(source, getCover(luid));
+ }
+
+ @Override
+ public void setAuthorCover(String author, String luid) throws IOException {
+ setAuthorCover(author, getCover(luid));
+ }
+
+ /**
+ * Set the source cover to the given story cover.
+ *
+ * @param source
+ * the source to change
+ * @param coverImage
+ * the cover image
+ */
+ synchronized void setSourceCover(String source, Image coverImage) {
+ File dir = getExpectedDir(source);
+ dir.mkdirs();
+ File cover = new File(dir, ".cover");
+ try {
+ Instance.getInstance().getCache().saveAsImage(coverImage, cover, true);
+ if (sourceCovers != null) {
+ sourceCovers.put(source, coverImage);
+ }
+ } catch (IOException e) {
+ Instance.getInstance().getTraceHandler().error(e);