git://git.nikiroo.be
/
fanfix.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fix some perf/space problems, add a cover for e621
[fanfix.git]
/
src
/
be
/
nikiroo
/
fanfix
/
supported
/
BasicSupport.java
diff --git
a/src/be/nikiroo/fanfix/supported/BasicSupport.java
b/src/be/nikiroo/fanfix/supported/BasicSupport.java
index ed7c4db1455bbff75c39c2b1fa95369ba8ba3968..b58f8fa380042c6165bd6dbd1d2d28909853a33d 100644
(file)
--- a/
src/be/nikiroo/fanfix/supported/BasicSupport.java
+++ b/
src/be/nikiroo/fanfix/supported/BasicSupport.java
@@
-14,8
+14,6
@@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
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.Instance;
import be.nikiroo.fanfix.bundles.Config;
import be.nikiroo.fanfix.bundles.StringId;
@@
-24,6
+22,7
@@
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Paragraph;
import be.nikiroo.fanfix.data.Paragraph.ParagraphType;
import be.nikiroo.fanfix.data.Story;
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;
/**
import be.nikiroo.utils.StringUtils;
/**
@@
-514,7
+513,7
@@
public abstract class BasicSupport {
String line = scan.next().trim();
boolean image = false;
if (line.startsWith("[") && line.endsWith("]")) {
String line = scan.next().trim();
boolean image = false;
if (line.startsWith("[") && line.endsWith("]")) {
- URL url = getImageUrl(source,
+ URL url = getImageUrl(
this,
source,
line.substring(1, line.length() - 1).trim());
if (url != null) {
paras.add(new Paragraph(url));
line.substring(1, line.length() - 1).trim());
if (url != null) {
paras.add(new Paragraph(url));
@@
-582,7
+581,7
@@
public abstract class BasicSupport {
&& Instance.getCoverDir() != null) {
try {
File fileCover = new File(Instance.getCoverDir(), subject);
&& Instance.getCoverDir() != null) {
try {
File fileCover = new File(Instance.getCoverDir(), subject);
- return getImage(fileCover.toURI().toURL(), subject);
+ return getImage(
null,
fileCover.toURI().toURL(), subject);
} catch (MalformedURLException e) {
}
}
} catch (MalformedURLException e) {
}
}
@@
-603,13
+602,13
@@
public abstract class BasicSupport {
}
}
}
}
- static BufferedImage getImage(URL source, String line) {
- URL url = getImageUrl(source, line);
+ static BufferedImage getImage(
BasicSupport support,
URL source, String line) {
+ URL url = getImageUrl(s
upport, s
ource, line);
if (url != null) {
InputStream in = null;
try {
in = Instance.getCache().open(url, getSupport(url), true);
if (url != null) {
InputStream in = null;
try {
in = Instance.getCache().open(url, getSupport(url), true);
- return I
mageIO.read
(in);
+ return I
OUtils.toImage
(in);
} catch (IOException e) {
} finally {
if (in != null) {
} catch (IOException e) {
} finally {
if (in != null) {
@@
-636,7
+635,7
@@
public abstract class BasicSupport {
* @return the image URL if found, or NULL
*
*/
* @return the image URL if found, or NULL
*
*/
- static URL getImageUrl(URL source, String line) {
+ static URL getImageUrl(
BasicSupport support,
URL source, String line) {
URL url = null;
if (line != null) {
URL url = null;
if (line != null) {
@@
-645,11
+644,11
@@
public abstract class BasicSupport {
if (source != null) {
path = new File(source.getFile()).getParent();
try {
if (source != null) {
path = new File(source.getFile()).getParent();
try {
- String
urlBase
= new File(new File(path), line.trim())
- .
toURI().toURL().toString
();
+ String
basePath
= new File(new File(path), line.trim())
+ .
getAbsolutePath
();
for (String ext : getImageExt(true)) {
for (String ext : getImageExt(true)) {
- if (new File(
urlBase
+ ext).exists()) {
- url = new File(
urlBase
+ ext).toURI().toURL();
+ if (new File(
basePath
+ ext).exists()) {
+ url = new File(
basePath
+ ext).toURI().toURL();
}
}
} catch (Exception e) {
}
}
} catch (Exception e) {
@@
-663,6
+662,7
@@
public abstract class BasicSupport {
for (String ext : getImageExt(true)) {
if (Instance.getCache().check(new URL(line + ext))) {
url = new URL(line + ext);
for (String ext : getImageExt(true)) {
if (Instance.getCache().check(new URL(line + ext))) {
url = new URL(line + ext);
+ break;
}
}
}
}
@@
-671,8
+671,7
@@
public abstract class BasicSupport {
for (String ext : getImageExt(true)) {
try {
url = new URL(line + ext);
for (String ext : getImageExt(true)) {
try {
url = new URL(line + ext);
- Instance.getCache().refresh(url,
- getSupport(url), true);
+ Instance.getCache().refresh(url, support, true);
break;
} catch (IOException e) {
// no image with this ext
break;
} catch (IOException e) {
// no image with this ext
@@
-688,7
+687,7
@@
public abstract class BasicSupport {
// refresh the cached file
if (url != null) {
try {
// refresh the cached file
if (url != null) {
try {
- Instance.getCache().refresh(url,
getSupport(url)
, true);
+ Instance.getCache().refresh(url,
support
, true);
} catch (IOException e) {
// woops, broken image
url = null;
} catch (IOException e) {
// woops, broken image
url = null;