* @param luid
* the Library UID of the story
*
- * @return the corresponding {@link Story}
+ * @return the corresponding {@link Story} or NULL if not found
*/
public Story getStory(String luid) {
if (luid != null) {
package be.nikiroo.fanfix.output;
+import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Paragraph;
}
}
- FileWriter writer = new FileWriter(new File(dir, "URL"));
+ BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(
+ new FileOutputStream(new File(dir, "URL")), "UTF-8"));
try {
if (meta != null) {
writer.write(meta.getUuid());
writer.close();
}
- writer = new FileWriter(new File(dir, "SUMMARY"));
+ writer = new BufferedWriter(new OutputStreamWriter(
+ new FileOutputStream(new File(dir, "SUMMARY")), "UTF-8"));
try {
String title = "";
if (meta != null && meta.getTitle() != null) {
package be.nikiroo.fanfix.output;
+import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStreamWriter;
import java.net.URL;
import javax.imageio.ImageIO;
import be.nikiroo.fanfix.data.Chapter;
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Paragraph;
-import be.nikiroo.fanfix.data.Story;
import be.nikiroo.fanfix.data.Paragraph.ParagraphType;
+import be.nikiroo.fanfix.data.Story;
import be.nikiroo.utils.IOUtils;
import be.nikiroo.utils.StringUtils;
class Epub extends BasicOutput {
private File tmpDir;
- private FileWriter writer;
+ private BufferedWriter writer;
private boolean inDialogue = false;
private boolean inNormal = false;
private File images;
protected void writeChapterHeader(Chapter chap) throws IOException {
String filename = String.format("%s%03d%s", "chapter-",
chap.getNumber(), ".xml");
- writer = new FileWriter(new File(tmpDir + "/OPS", filename));
+ writer = new BufferedWriter(new OutputStreamWriter(
+ new FileOutputStream(new File(tmpDir + File.separator + "OPS",
+ filename)), "UTF-8"));
inDialogue = false;
inNormal = false;
try {
package be.nikiroo.fanfix.output;
+import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStreamWriter;
import javax.imageio.ImageIO;
class Html extends BasicOutput {
private File dir;
- protected FileWriter writer;
+ protected BufferedWriter writer;
private boolean inDialogue = false;
private boolean inNormal = false;
target.mkdir();
dir = target;
- targetName = new File(targetName, "index").getPath();
targetName += getDefaultExtension();
target = new File(targetDir, targetName);
- writer = new FileWriter(target);
+ writer = new BufferedWriter(new OutputStreamWriter(
+ new FileOutputStream(target), "UTF-8"));
try {
super.process(story, targetDir, targetNameOrig);
} finally {
package be.nikiroo.fanfix.output;
+import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import javax.imageio.ImageIO;
public static void writeInfo(File targetDir, String targetName,
MetaData meta) throws IOException {
File info = new File(targetDir, targetName + ".info");
- FileWriter infoWriter = new FileWriter(info);
+ BufferedWriter infoWriter = new BufferedWriter(new OutputStreamWriter(
+ new FileOutputStream(info), "UTF-8"));
if (meta != null) {
try {
}
}
- private static void writeMeta(FileWriter writer, String key, String value)
- throws IOException {
+ private static void writeMeta(BufferedWriter writer, String key,
+ String value) throws IOException {
if (value == null) {
value = "";
}
package be.nikiroo.fanfix.output;
+import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.bundles.Config;
import be.nikiroo.fanfix.bundles.StringId;
import be.nikiroo.fanfix.data.Chapter;
import be.nikiroo.fanfix.data.MetaData;
-import be.nikiroo.fanfix.data.Story;
import be.nikiroo.fanfix.data.Paragraph.ParagraphType;
+import be.nikiroo.fanfix.data.Story;
class LaTeX extends BasicOutput {
- protected FileWriter writer;
+ protected BufferedWriter writer;
private boolean lastWasQuote = false;
// quote chars
File target = new File(targetDir, targetName);
- writer = new FileWriter(target);
+ writer = new BufferedWriter(new OutputStreamWriter(
+ new FileOutputStream(target), "UTF-8"));
try {
super.process(story, targetDir, targetNameOrig);
} finally {
package be.nikiroo.fanfix.output;
+import java.io.BufferedWriter;
import java.io.File;
-import java.io.FileWriter;
+import java.io.FileOutputStream;
import java.io.IOException;
+import java.io.OutputStreamWriter;
import java.net.URL;
import be.nikiroo.fanfix.Instance;
import be.nikiroo.fanfix.data.Chapter;
import be.nikiroo.fanfix.data.MetaData;
import be.nikiroo.fanfix.data.Paragraph;
-import be.nikiroo.fanfix.data.Story;
import be.nikiroo.fanfix.data.Paragraph.ParagraphType;
+import be.nikiroo.fanfix.data.Story;
class Text extends BasicOutput {
- protected FileWriter writer;
+ protected BufferedWriter writer;
protected File targetDir;
@Override
File target = new File(targetDir, targetName);
- writer = new FileWriter(target);
+ writer = new BufferedWriter(new OutputStreamWriter(
+ new FileOutputStream(target), "UTF-8"));
try {
super.process(story, targetDir, targetNameOrig);
} finally {
}
// return new luid
- public String imprt(String luid) {
+ public String imprt(String luid) throws IOException {
try {
Story story = Instance.getLibrary().getStory(luid);
- story = lib.save(story);
- return story.getMeta().getLuid();
+ if (story != null) {
+ story = lib.save(story);
+ return story.getMeta().getLuid();
+ } else {
+ throw new IOException("Cannot find story in Library: " + luid);
+ }
} catch (IOException e) {
- Instance.syserr(new IOException(
+ throw new IOException(
"Cannot import story from library to LocalReader library: "
- + luid, e));
+ + luid, e);
}
-
- return null;
}
- public File getTarget(String luid) {
+ public File getTarget(String luid) throws IOException {
MetaData meta = lib.getInfo(luid);
File file = lib.getFile(luid);
if (file == null) {