Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEAT: JHOVE ready TIFF library #1

Merged
merged 5 commits into from
Jul 8, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
FEAT: JHOVE ready TIFF library
- factored lower level TIFF reader so that it supports different data source methods (e.g. input stream, file, etc.);
- added a slightly hacky set of methods so that file paths not required for TIFF validation;
- took OPF ownership of Maven publication for permissions; and
- added myself to the developer list.
  • Loading branch information
carlwilson committed Jul 2, 2020
commit 4444f3b92605529d38d52a315e277469c56d589e
19 changes: 12 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.easyinnova</groupId>
<groupId>org.openpreservation</groupId>
<artifactId>tifflibrary4java</artifactId>
<version>1.9.7</version>
<version>1.9.8</version>
<packaging>jar</packaging>
<name>Tiff Library 4 Java</name>
<description>A library to read and give access to Tiff files.</description>
<url>https://github.com/easyinnova/Tiff-Library-4J/</url>
<url>https://github.com/openpreserve/Tiff-Library-4J.git/</url>
<inceptionYear>2015</inceptionYear>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -55,6 +55,12 @@
</dependency>
</dependencies>
<developers>
<developer>
<name>Carl Wilson</name>
<email>carl@openpreservation.org</email>
<organization>Open Preservation Foundation</organization>
<organizationUrl>https://openpreservation.org/</organizationUrl>
</developer>
<developer>
<name>Víctor Muñoz Solà</name>
<email>victormunoz@easyinnova.com</email>
Expand All @@ -63,10 +69,9 @@
</developer>
</developers>
<scm>
<connection>scm:git:git@github.com:easyinnova/Tiff-Library-4J.git</connection>
<developerConnection>scm:git:git@github.com:easyinnova/Tiff-Library-4J.git
</developerConnection>
<url>git@github.com:easyinnova/Tiff-Library-4J.git</url>
<connection>scm:git:git@github.com:openpreserve/Tiff-Library-4J.git</connection>
<developerConnection>scm:git:git@github.com:openpreserve/Tiff-Library-4J.git</developerConnection>
<url>git@github.com:openpreserve/Tiff-Library-4J.git</url>
</scm>
<distributionManagement>
<snapshotRepository>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,15 @@ public RandomAccessFileInputStream(File file) throws FileNotFoundException {
randomAccessFile = new RandomAccessFile(file, "r");
}

public RandomAccessFileInputStream(final RandomAccessFile raf) throws FileNotFoundException {
this(raf, "");
}

public RandomAccessFileInputStream(final RandomAccessFile raf, final String path) throws FileNotFoundException {
this.path = path;
this.randomAccessFile = raf;
}

public String getPath() {
return path;
}
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/com/easyinnova/tiff/io/TiffInputStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

/**
* The Class TiffInputStream.
Expand Down Expand Up @@ -96,7 +97,15 @@ public TiffInputStream(File file) throws FileNotFoundException {
fileOffset = 0;
buffer = new PagedInputBuffer(this);
}


public TiffInputStream(RandomAccessFile raf) throws FileNotFoundException {
internalFile = null;
internalFileBig = new RandomAccessFileInputStream(raf);
byteOrder = ByteOrder.BIG_ENDIAN;
fileOffset = 0;
buffer = new PagedInputBuffer(this);
}

/**
* Gets the byte order.
*
Expand Down
51 changes: 46 additions & 5 deletions src/main/java/com/easyinnova/tiff/reader/TiffReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import com.easyinnova.tiff.profiles.TiffITProfile;

import java.io.File;
import java.io.RandomAccessFile;
import java.lang.reflect.InvocationTargetException;
import java.nio.file.Files;
import java.nio.file.Paths;
Expand Down Expand Up @@ -171,7 +172,52 @@ public int readFile(String filename, boolean validate) {
try {
if (Files.exists(Paths.get(filename))) {
data = new TiffInputStream(new File(filename));
result = this.validate(validate);
} else {
// File not found
result = -1;
tiffModel.setFatalError(true, "File not found");
}
} catch (Exception ex) {
// IO exception
result = -2;
tiffModel.setFatalError(true, "IO Exception");
}

return result;
}

/**
* Parses a Tiff File and create an internal model representation.
*
* @param filename the Tiff filename
* @return Error code (0: successful, -1: file not found, -2: IO exception)
*/
public int readFile(RandomAccessFile raf, boolean validate) {
int result = 0;

try {
data = new TiffInputStream(raf);
result = this.validate(validate);
} catch (Exception ex) {
// IO exception
result = -2;
tiffModel.setFatalError(true, "IO Exception");
}

return result;
}

/**
* Parses a Tiff File and create an internal model representation.
*
* @param filename the Tiff filename
* @return Error code (0: successful, -1: file not found, -2: IO exception)
*/
private int validate(boolean validate) {
int result = 0;

try {
tiffModel = new TiffDocument();
validation = new ValidationResult(validate);
tiffModel.setSize(data.size());
Expand All @@ -198,11 +244,6 @@ public int readFile(String filename, boolean validate) {
}

data.close();
} else {
// File not found
result = -1;
tiffModel.setFatalError(true, "File not found");
}
} catch (Exception ex) {
// IO exception
result = -2;
Expand Down