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
commitad7bde8b02f9f17ff3f0c13800fba79b8d7e5ce1 (patch)
treecefab76b76b5f34f702af2f80ec2836c2843ace5
parentf7a0f211450949040b5f2f144cb39df74c025674 (diff)
downloadEssentials-ad7bde8b02f9f17ff3f0c13800fba79b8d7e5ce1.tar
Essentials-ad7bde8b02f9f17ff3f0c13800fba79b8d7e5ce1.tar.gz
Essentials-ad7bde8b02f9f17ff3f0c13800fba79b8d7e5ce1.tar.lz
Essentials-ad7bde8b02f9f17ff3f0c13800fba79b8d7e5ce1.tar.xz
Essentials-ad7bde8b02f9f17ff3f0c13800fba79b8d7e5ce1.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