import be.nikiroo.fanfix.supported.BasicSupport;
import be.nikiroo.utils.IOUtils;
import be.nikiroo.utils.MarkableFileInputStream;
-import be.nikiroo.utils.StringUtils;
/**
* This cache will manage Internet (and local) downloads, as well as put the
* @param stable
* TRUE for more stable resources, FALSE when they often change
*
- * @return the opened resource
+ * @return the opened resource, NOT NULL
*
* @throws IOException
* in case of I/O error
*/
public InputStream open(URL url, BasicSupport support, boolean stable)
throws IOException {
+ // MUST NOT return null
return open(url, support, stable, url);
}
* @param originalUrl
* the original {@link URL} used to locate the cached resource
*
- * @return the opened resource
+ * @return the opened resource, NOT NULL
*
* @throws IOException
* in case of I/O error
*/
public InputStream open(URL url, BasicSupport support, boolean stable,
URL originalUrl) throws IOException {
+ // MUST NOT return null
try {
InputStream in = load(originalUrl, false, stable);
if (in == null) {
+ (url == null ? "null" : url.toString()), e);
}
+ // Was just saved, can load old, so, will not be null
in = load(originalUrl, true, stable);
}
* @param stable
* TRUE for more stable resources, FALSE when they often change
*
- * @return TRUE if it was pre-downloaded
- *
* @throws IOException
* in case of I/O error
*/
* in case of I/O error
*/
public void saveAsImage(URL url, File target) throws IOException {
- URL cachedUrl = new URL(url.toString()
- + "."
- + Instance.getConfig().getString(Config.IMAGE_FORMAT_CONTENT)
- .toLowerCase());
+ URL cachedUrl = new URL(url.toString());
File cached = getCached(cachedUrl);
if (!cached.exists() || isOld(cached, true)) {
- InputStream imageIn = Instance.getCache().open(url, null, true);
- ImageIO.write(StringUtils.toImage(imageIn), Instance.getConfig()
+ InputStream imageIn = open(url, null, true);
+ ImageIO.write(IOUtils.toImage(imageIn), Instance.getConfig()
.getString(Config.IMAGE_FORMAT_CONTENT).toLowerCase(),
cached);
}
*
* @param url
* the resource to open
- * @return the opened resource
+ *
+ * @return the opened resource if found, NULL i not
+ *
* @throws IOException
* in case of I/O error
*/
import java.util.Map.Entry;
import java.util.Scanner;
-import javax.imageio.ImageIO;
-
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.bundles.Config;
import be.nikiroo.fanfix.bundles.StringId;
import be.nikiroo.fanfix.data.Paragraph;
import be.nikiroo.fanfix.data.Paragraph.ParagraphType;
import be.nikiroo.fanfix.data.Story;
+import be.nikiroo.utils.IOUtils;
import be.nikiroo.utils.StringUtils;
/**
InputStream in = null;
try {
in = Instance.getCache().open(url, getSupport(url), true);
- return ImageIO.read(in);
+ return IOUtils.toImage(in);
} catch (IOException e) {
} finally {
if (in != null) {
package be.nikiroo.fanfix.supported;
+import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
meta.setSubject("");
meta.setType(getType().toString());
meta.setImageDocument(true);
- meta.setCover(null);
+ meta.setCover(getCover(source));
return meta;
}
return true;
}
+ private BufferedImage getCover(URL source) throws IOException {
+ InputStream in = Instance.getCache().open(source, this, true);
+ String images = getChapterContent(new URL(source.toString() + "?page="
+ + 1), in, 1);
+ if (!images.isEmpty()) {
+ int pos = images.indexOf('\n');
+ if (pos >= 0) {
+ images = images.substring(1, pos - 1);
+ return getImage(this, null, images);
+ }
+ }
+
+ return null;
+ }
+
private String getAuthor(URL source, InputStream in) throws IOException {
String author = getLine(in, "href=\"/post/show/", 0);
if (author != null) {