summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKHobbits <rob@khobbits.co.uk>2013-01-14 08:21:03 +0000
committerKHobbits <rob@khobbits.co.uk>2013-01-14 08:21:03 +0000
commitf8cf3be87fb663a9adcb39271ee178727722de11 (patch)
treea3e1906d95ac2c5e025109f79ba1f1c927a65377
parentada266a0f9a674508311b38cf9ec890484276d89 (diff)
downloadEssentials-f8cf3be87fb663a9adcb39271ee178727722de11.tar
Essentials-f8cf3be87fb663a9adcb39271ee178727722de11.tar.gz
Essentials-f8cf3be87fb663a9adcb39271ee178727722de11.tar.lz
Essentials-f8cf3be87fb663a9adcb39271ee178727722de11.tar.xz
Essentials-f8cf3be87fb663a9adcb39271ee178727722de11.zip
Better handle initial book.txt creation.
-rw-r--r--Essentials/src/com/earth2me/essentials/textreader/BookInput.java62
1 files changed, 33 insertions, 29 deletions
diff --git a/Essentials/src/com/earth2me/essentials/textreader/BookInput.java b/Essentials/src/com/earth2me/essentials/textreader/BookInput.java
index d8df79ec2..b0fedbf86 100644
--- a/Essentials/src/com/earth2me/essentials/textreader/BookInput.java
+++ b/Essentials/src/com/earth2me/essentials/textreader/BookInput.java
@@ -22,7 +22,39 @@ public class BookInput implements IText
{
file = new File(ess.getDataFolder(), filename + ".txt");
}
- if (file.exists())
+ if (!file.exists())
+ {
+ if (createFile)
+ {
+ final InputStream input = ess.getResource(filename + ".txt");
+ final OutputStream output = new FileOutputStream(file);
+ try
+ {
+ final byte[] buffer = new byte[1024];
+ int length = input.read(buffer);
+ while (length > 0)
+ {
+ output.write(buffer, 0, length);
+ length = input.read(buffer);
+ }
+ }
+ finally
+ {
+ output.close();
+ input.close();
+ }
+ ess.getLogger().info("File " + filename + ".txt does not exist. Creating one for you.");
+ }
+ }
+ if (!file.exists())
+ {
+ lastChange = 0;
+ lines = Collections.emptyList();
+ chapters = Collections.emptyList();
+ bookmarks = Collections.emptyMap();
+ throw new FileNotFoundException("Could not create " + filename + ".txt");
+ }
+ else
{
lastChange = file.lastModified();
boolean readFromfile;
@@ -74,34 +106,6 @@ public class BookInput implements IText
}
}
}
- else
- {
- lastChange = 0;
- lines = Collections.emptyList();
- chapters = Collections.emptyList();
- bookmarks = Collections.emptyMap();
- if (createFile)
- {
- final InputStream input = ess.getResource(filename + ".txt");
- final OutputStream output = new FileOutputStream(file);
- try
- {
- final byte[] buffer = new byte[1024];
- int length = input.read(buffer);
- while (length > 0)
- {
- output.write(buffer, 0, length);
- length = input.read(buffer);
- }
- }
- finally
- {
- output.close();
- input.close();
- }
- throw new FileNotFoundException("File " + filename + ".txt does not exist. Creating one for you.");
- }
- }
}
@Override