Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Commit

Permalink
* add eclipse project files
Browse files Browse the repository at this point in the history
* add support for uncompressing from an input stream
  • Loading branch information
DerManoMann committed Jun 27, 2011
1 parent 6f32323 commit 17cb572
Show file tree
Hide file tree
Showing 8 changed files with 139 additions and 56 deletions.
17 changes: 9 additions & 8 deletions unrar/.classpath
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java"/>
<classpathentry kind="src" output="target/test-classes" path="src/test/java"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry including="**/*.java" kind="src" path="src/main/java"/>
<classpathentry kind="con" path="org.eclipse.iam.jdt.core.mavenClasspathContainer"/>
<classpathentry kind="con" path="org.maven.ide.eclipse.MAVEN2_CLASSPATH_CONTAINER"/>
<classpathentry kind="lib" path="lib/ij.jar"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
64 changes: 35 additions & 29 deletions unrar/.project
Original file line number Diff line number Diff line change
@@ -1,29 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>unrar</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.devzuz.q.maven.jdt.core.mavenIncrementalBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
<nature>org.devzuz.q.maven.jdt.core.mavenNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>unrar</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.devzuz.q.maven.jdt.core.mavenIncrementalBuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.maven.ide.eclipse.maven2Builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.iam.jdt.core.mavenIncrementalBuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.devzuz.q.maven.jdt.core.mavenNature</nature>
<nature>org.maven.ide.eclipse.maven2Nature</nature>
<nature>org.eclipse.iam.jdt.core.mavenNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
</natures>
</projectDescription>
24 changes: 12 additions & 12 deletions unrar/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
#Sun Jul 12 17:31:10 CEST 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.5
#Mon Jun 27 16:38:40 NZST 2011
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.6
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.6
Binary file added unrar/lib/ij.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions unrar/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,22 @@
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<type>jar</type>
<scope>test</scope>
<optional>false</optional>
</dependency>
<dependency>
<groupId>org.javolution</groupId>
<artifactId>javolution</artifactId>
<version>5.2.6</version>
<type>jar</type>
<optional>false</optional>
</dependency>
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging-api</artifactId>
<version>1.0.4</version>
<type>jar</type>
<optional>false</optional>
</dependency>
</dependencies>
Expand Down
8 changes: 8 additions & 0 deletions unrar/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
unrar
=====

Adds support to read a rar from a given InputStream.

Additional dependencies
-----------------------
* ij: http://rsbweb.nih.gov/ij/
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.sli.unrar.io;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import ij.io.RandomAccessStream;

import de.innosystec.unrar.io.IReadOnlyAccess;

/**
* InputStream based implementation of the <code>IReadOnlyAccess</code> interface.
*
* @see http://rsbweb.nih.gov/ij/
* @author martinr
*/
public class InputStreamReadOnlyAccessFile implements IReadOnlyAccess {
private RandomAccessStream is;

/**
* Create new instance.
*
* @param is The input stream to wrap.
*/
public InputStreamReadOnlyAccessFile(final InputStream is) {
this.is = new RandomAccessStream(new BufferedInputStream(is));
}

@Override
public long getPosition() throws IOException {
return is.getLongFilePointer();
}

@Override
public void setPosition(long pos) throws IOException {
is.seek(pos);
}

@Override
public int read() throws IOException {
return is.read();
}

@Override
public int read(byte[] buffer, int off, int count) throws IOException {
return is.read(buffer, off, count);
}

@Override
public int readFully(byte[] buffer, int count) throws IOException {
is.readFully(buffer, count);
return count;
}

@Override
public void close() throws IOException {
is.close();
}

}
18 changes: 11 additions & 7 deletions unrar/src/main/java/de/innosystec/unrar/Archive.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import java.io.Closeable;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
Expand Down Expand Up @@ -114,14 +115,18 @@ public File getFile() {
return file;
}

void setFile(File file) throws IOException {
void setFile(File file) throws IOException {
this.file = file;
setFile(new ReadOnlyAccessFile(file), file.length());
}

void setFile(IReadOnlyAccess file, long length) throws IOException {
totalPackedSize = 0L;
totalPackedRead = 0L;
close();
rof = new ReadOnlyAccessFile(file);
rof = file;
try {
readHeaders();
readHeaders(length);
} catch (Exception e) {
logger.log(Level.WARNING,
"exception in archive constructor maybe file is encrypted "
Expand Down Expand Up @@ -197,19 +202,18 @@ public boolean isEncrypted() {

/**
* Read the headers of the archive
*
*
* @param fileLength Length of file.
* @throws RarException
*/
private void readHeaders() throws IOException, RarException {
private void readHeaders(long fileLength) throws IOException, RarException {
markHead = null;
newMhd = null;
endHeader = null;
headers.clear();
currentHeaderIndex = 0;
int toRead = 0;

long fileLength = this.file.length();

while (true) {
int size = 0;
long newpos = 0;
Expand Down

0 comments on commit 17cb572

Please sign in to comment.