- private static final long serialVersionUID = -2547388204667088033L;
-
- /**
- * File name relative to the immediate parent directory.
- */
- public final String fileName;
-
- /**
- * File length in bytes.
- */
- private long fileLength;
-
- private transient boolean metaInfoVerified;
-
- public AbstractFile(final File parentDirectory, final String fileName)
- throws Exception {
- this.fileName = fileName;
- ensureFileMetainfoIsUpToDate(parentDirectory);
- }
-
- /**
- * @return <code>true</code> if file metadata was updated.
- */
- public boolean ensureFileMetainfoIsUpToDate(final File parentDirectory)
- throws Exception {
- if (!isMetainfoUpToDate(parentDirectory)) {
- fileLength = getFile(parentDirectory).length();
- updateFileMetainfo(parentDirectory);
- metaInfoVerified = true;
- return true;
- }
- return false;
- };
-
- public boolean fileExists(final File parentDirectory) {
- return getFile(parentDirectory).exists();
- }
-
- public File getFile(final File parentDirectory) {
- return new File(parentDirectory.getAbsolutePath(), fileName);
- }
-
- public String getFileExtension() {
- return FilePathParser.getFileExtension(fileName);
- }
-
- public long getFileLength() {
- return fileLength;
- }
-
- private boolean isMetainfoUpToDate(final java.io.File parentDirectory)
- throws IOException {
-
- if (metaInfoVerified)
- return true;
-
- final File file = getFile(parentDirectory);
-
- // first check that file exists at all
- if (!file.exists()) {
- System.out.println(file);
- throw new RuntimeException("Picture file by name \"" + fileName
- + "\" does not exist in the parent directory \""
- + parentDirectory.getAbsolutePath() + "\"");
- }
-
- // check that file length is the same as before
- if (file.length() != fileLength)
- return false;
-
- metaInfoVerified = true;
- return true;
- }
-
- public boolean isMetaInfoVerified() {
- return metaInfoVerified;
- }
-
- protected abstract void updateFileMetainfo(final File parentDirectory)
- throws Exception;
+ private static final long serialVersionUID = -2547388204667088033L;
+
+ /**
+ * File name relative to the immediate parent directory.
+ */
+ public final String fileName;
+
+ /**
+ * File length in bytes.
+ */
+ private long fileLength = -1;
+
+ private transient boolean metaInfoVerified;
+
+ AbstractFile(final File parentDirectory, final String fileName)
+ throws Exception {
+ this.fileName = fileName;
+ ensureFileMetainfoIsUpToDate(parentDirectory);
+ }
+
+ /**
+ * @return <code>true</code> if file metadata was updated.
+ */
+ public boolean ensureFileMetainfoIsUpToDate(final File parentDirectory)
+ throws Exception {
+ if (!isMetainfoUpToDate(parentDirectory)) {
+ fileLength = getFile(parentDirectory).length();
+ updateFileMetainfo(parentDirectory);
+ metaInfoVerified = true;
+ return true;
+ }
+ return false;
+ }
+
+ public boolean fileExists(final File parentDirectory) {
+ return getFile(parentDirectory).exists();
+ }
+
+ File getFile(final File parentDirectory) {
+ return new File(parentDirectory.getAbsolutePath(), fileName);
+ }
+
+ public String getFileExtension() {
+ return FilePathParser.getFileExtension(fileName);
+ }
+
+ public long getFileLength() {
+ return fileLength;
+ }
+
+ private boolean isMetainfoUpToDate(final java.io.File parentDirectory) {
+
+ if (metaInfoVerified)
+ return true;
+
+ final File file = getFile(parentDirectory);
+
+ // first check that file exists at all
+ if (!file.exists()) {
+ System.out.println(file);
+ throw new RuntimeException("Picture file by name \"" + fileName
+ + "\" does not exist in the parent directory \""
+ + parentDirectory.getAbsolutePath() + "\"");
+ }
+
+ // check that file length is the same as before
+ if (file.length() != fileLength)
+ return false;
+
+ metaInfoVerified = true;
+ return true;
+ }
+
+ public boolean isMetaInfoVerified() {
+ return metaInfoVerified;
+ }
+
+ protected abstract void updateFileMetainfo(final File parentDirectory)
+ throws Exception;