+ 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.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.getCache().saveAsImage(coverImage, cover, true);
+ if (sourceCovers != null) {
+ sourceCovers.put(source, coverImage);
+ }
+ } catch (IOException e) {
+ Instance.getTraceHandler().error(e);
+ }
+ }
+
+ /**
+ * Set the author cover to the given story cover.
+ *
+ * @param author
+ * the author to change
+ * @param coverImage
+ * the cover image
+ */
+ synchronized void setAuthorCover(String author, Image coverImage) {
+ File cover = getAuthorCoverFile(author);
+ cover.getParentFile().mkdirs();