import java.net.CookieStore;
import java.net.HttpCookie;
import java.net.HttpURLConnection;
-import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
import be.nikiroo.fanfix.bundles.Config;
import be.nikiroo.fanfix.supported.BasicSupport;
import be.nikiroo.utils.IOUtils;
+import be.nikiroo.utils.ImageUtils;
import be.nikiroo.utils.MarkableFileInputStream;
/**
}
/**
- * Open a resource (will load it from the cache if possible, or save it into
- * the cache after downloading if not) as an Image, then save it where
- * requested.
- * <p>
- * This version will not always work properly if the original file was not
- * downloaded before.
+ * Save the given resource as an image on disk using the default image
+ * format for content.
*
* @param url
- * the resource to open
- *
- * @return the opened resource image
+ * the resource
+ * @param target
+ * the target file
*
* @throws IOException
* in case of I/O error
if (!cached.exists() || isOld(cached, true)) {
InputStream imageIn = open(url, null, true);
- ImageIO.write(IOUtils.toImage(imageIn), Instance.getConfig()
+ ImageIO.write(ImageUtils.fromStream(imageIn), Instance.getConfig()
.getString(Config.IMAGE_FORMAT_CONTENT).toLowerCase(),
cached);
}
*
* @param uniqueID
* the unique ID
- *
+ *
* @return the content or NULL
*/
public InputStream getFromCache(String uniqueID) {
*
* @param url
* the resource to open
+ * @param allowTooOld
+ * allow files even if they are considered too old
+ * @param stable
+ * a stable file (that dones't change too often) -- parameter
+ * used to check if the file is too old to keep or not
*
* @return the opened resource if found, NULL i not
*
* @throws IOException
* in case of I/O error
*/
- private InputStream load(URL url, boolean allowOld, boolean stable)
+ private InputStream load(URL url, boolean allowTooOld, boolean stable)
throws IOException {
File cached = getCached(url);
- if (cached.exists() && !isOld(cached, stable)) {
+ if (cached.exists() && (allowTooOld || !isOld(cached, stable))) {
return new MarkableFileInputStream(new FileInputStream(cached));
}
*
* @throws IOException
* in case of I/O error
- * @throws URISyntaxException
*/
private void save(URL url, BasicSupport support, URL originalUrl)
throws IOException {
*
* @param url
* the url
+ *
* @return the cached version if present, NULL if not
*/
private File getCached(URL url) {
* Get the cache resource from the cache if it is present for this unique
* ID.
*
- * @param url
- * the url
+ * @param uniqueID
+ * the id
+ *
* @return the cached version if present, NULL if not
*/
private File getCached(String uniqueID) {