Skip to content

Commit 6cd9621

Browse files
committed
Add support for entries larger than 2GB (Closes #14)
1 parent f28be8b commit 6cd9621

File tree

14 files changed

+40
-30
lines changed

14 files changed

+40
-30
lines changed

iso9660-ant-tasks/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<artifactId>java-iso-tools-parent</artifactId>
2323
<groupId>com.github.stephenc.java-iso-tools</groupId>
24-
<version>2.0.2-SNAPSHOT</version>
24+
<version>2.1.0-SNAPSHOT</version>
2525
</parent>
2626
<modelVersion>4.0.0</modelVersion>
2727

@@ -37,7 +37,7 @@
3737
<dependency>
3838
<groupId>com.github.stephenc.java-iso-tools</groupId>
3939
<artifactId>iso9660-writer</artifactId>
40-
<version>2.0.2-SNAPSHOT</version>
40+
<version>2.1.0-SNAPSHOT</version>
4141
</dependency>
4242
</dependencies>
4343

iso9660-maven-plugin/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>com.github.stephenc.java-iso-tools</groupId>
2525
<artifactId>java-iso-tools-parent</artifactId>
26-
<version>2.0.2-SNAPSHOT</version>
26+
<version>2.1.0-SNAPSHOT</version>
2727
</parent>
2828

2929
<artifactId>iso9660-maven-plugin</artifactId>
@@ -44,7 +44,7 @@
4444
<dependency>
4545
<groupId>com.github.stephenc.java-iso-tools</groupId>
4646
<artifactId>iso9660-writer</artifactId>
47-
<version>2.0.2-SNAPSHOT</version>
47+
<version>2.1.0-SNAPSHOT</version>
4848
</dependency>
4949
<dependency>
5050
<groupId>org.codehaus.plexus</groupId>

iso9660-vfs-impl/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>com.github.stephenc.java-iso-tools</groupId>
2525
<artifactId>java-iso-tools-parent</artifactId>
26-
<version>2.0.2-SNAPSHOT</version>
26+
<version>2.1.0-SNAPSHOT</version>
2727
</parent>
2828

2929
<artifactId>iso9660-vfs-impl</artifactId>
@@ -52,7 +52,7 @@
5252
<dependency>
5353
<groupId>com.github.stephenc.java-iso-tools</groupId>
5454
<artifactId>loop-fs-iso-impl</artifactId>
55-
<version>2.0.2-SNAPSHOT</version>
55+
<version>2.1.0-SNAPSHOT</version>
5656
</dependency>
5757
</dependencies>
5858

iso9660-writer/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
<parent>
2424
<groupId>com.github.stephenc.java-iso-tools</groupId>
2525
<artifactId>java-iso-tools-parent</artifactId>
26-
<version>2.0.2-SNAPSHOT</version>
26+
<version>2.1.0-SNAPSHOT</version>
2727
</parent>
2828

2929
<artifactId>iso9660-writer</artifactId>
@@ -45,7 +45,7 @@
4545
<dependency>
4646
<groupId>com.github.stephenc.java-iso-tools</groupId>
4747
<artifactId>sabre</artifactId>
48-
<version>2.0.2-SNAPSHOT</version>
48+
<version>2.1.0-SNAPSHOT</version>
4949
</dependency>
5050
<dependency>
5151
<groupId>junit</groupId>
@@ -62,7 +62,7 @@
6262
<dependency>
6363
<groupId>com.github.stephenc.java-iso-tools</groupId>
6464
<artifactId>iso9660-vfs-impl</artifactId>
65-
<version>2.0.2-SNAPSHOT</version>
65+
<version>2.1.0-SNAPSHOT</version>
6666
<scope>test</scope>
6767
</dependency>
6868
</dependencies>

loop-fs-api/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<artifactId>java-iso-tools-parent</artifactId>
2323
<groupId>com.github.stephenc.java-iso-tools</groupId>
24-
<version>2.0.2-SNAPSHOT</version>
24+
<version>2.1.0-SNAPSHOT</version>
2525
</parent>
2626
<modelVersion>4.0.0</modelVersion>
2727

loop-fs-iso-impl/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
<parent>
2222
<artifactId>java-iso-tools-parent</artifactId>
2323
<groupId>com.github.stephenc.java-iso-tools</groupId>
24-
<version>2.0.2-SNAPSHOT</version>
24+
<version>2.1.0-SNAPSHOT</version>
2525
</parent>
2626
<modelVersion>4.0.0</modelVersion>
2727

@@ -50,7 +50,7 @@
5050
<dependency>
5151
<groupId>com.github.stephenc.java-iso-tools</groupId>
5252
<artifactId>loop-fs-spi</artifactId>
53-
<version>2.0.2-SNAPSHOT</version>
53+
<version>2.1.0-SNAPSHOT</version>
5454
</dependency>
5555
<dependency>
5656
<groupId>junit</groupId>

loop-fs-iso-impl/src/main/java/com/github/stephenc/javaisotools/loopfs/iso9660/EntryInputStream.java

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@ class EntryInputStream extends InputStream {
3333
private Iso9660FileSystem fileSystem;
3434

3535
// current position within entry data
36-
private int pos;
36+
private long pos;
3737

3838
// number of remaining bytes within entry
39-
private int rem;
39+
private long rem;
4040

4141
EntryInputStream(final Iso9660FileEntry entry, final Iso9660FileSystem fileSystem) {
4242
this.fileSystem = fileSystem;
4343
this.entry = entry;
4444
this.pos = 0;
45-
this.rem = (int) entry.getSize();
45+
this.rem = entry.getSize();
4646
}
4747

4848
public int read(final byte b[], final int off, final int len) throws IOException {
@@ -58,7 +58,8 @@ public int read(final byte b[], final int off, final int len) throws IOException
5858
int toRead = len;
5959

6060
if (toRead > this.rem) {
61-
toRead = this.rem;
61+
// down cast is safe as toRead is int and greater than this.rem
62+
toRead = (int)this.rem;
6263
}
6364

6465
int read;
@@ -94,7 +95,7 @@ public int read() throws IOException {
9495
public long skip(final long n) {
9596
ensureOpen();
9697

97-
final int len = (n > this.rem) ? this.rem : (int) n;
98+
final long len = (n > this.rem) ? this.rem : n;
9899

99100
this.pos += len;
100101
this.rem -= len;
@@ -107,13 +108,19 @@ public long skip(final long n) {
107108
}
108109

109110
public int available() {
110-
return Math.max(this.rem, 0);
111+
if (this.rem > Integer.MAX_VALUE) {
112+
return Integer.MAX_VALUE;
113+
} else if (this.rem < 0) {
114+
return 0;
115+
} else {
116+
return (int) this.rem;
117+
}
111118
}
112119

113-
public int size() {
120+
public long size() {
114121
ensureOpen();
115122

116-
return (int) this.entry.getSize();
123+
return this.entry.getSize();
117124
}
118125

119126
public void close() {

loop-fs-iso-impl/src/main/java/com/github/stephenc/javaisotools/loopfs/iso9660/Iso9660FileEntry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public final class Iso9660FileEntry implements FileEntry {
3232
private String parentPath;
3333
private final int entryLength;
3434
private final long startSector;
35-
private final int dataLength;
35+
private final long dataLength;
3636
private final long lastModifiedTime;
3737
private final int flags;
3838
private final String identifier;
@@ -63,7 +63,7 @@ public Iso9660FileEntry(final Iso9660FileSystem fileSystem, final String parentP
6363
this.entryLength = Util.getUInt8(block, offset + 1);
6464
//this.extAttributeLength = Util.getUInt8(block, offset+2);
6565
this.startSector = Util.getUInt32LE(block, offset + 3);
66-
this.dataLength = (int) Util.getUInt32LE(block, offset + 11);
66+
this.dataLength = Util.getUInt32LE(block, offset + 11);
6767
this.lastModifiedTime = Util.getDateTime(block, offset + 19);
6868
this.flags = Util.getUInt8(block, offset + 26);
6969
//this.fileUnitSize = Util.getUInt8(block, offset+27);

loop-fs-iso-impl/src/main/java/com/github/stephenc/javaisotools/loopfs/iso9660/Iso9660FileSystem.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ public InputStream getInputStream(Iso9660FileEntry entry) {
4949
}
5050

5151
byte[] getBytes(Iso9660FileEntry entry) throws IOException {
52+
if (entry.getSize() > Integer.MAX_VALUE) {
53+
throw new IOException("Entry too large");
54+
}
5255
int size = (int) entry.getSize();
5356

5457
byte[] buf = new byte[size];
@@ -58,7 +61,7 @@ byte[] getBytes(Iso9660FileEntry entry) throws IOException {
5861
return buf;
5962
}
6063

61-
int readBytes(Iso9660FileEntry entry, int entryOffset, byte[] buffer, int bufferOffset, int len)
64+
int readBytes(Iso9660FileEntry entry, long entryOffset, byte[] buffer, int bufferOffset, int len)
6265
throws IOException {
6366
long startPos = (entry.getStartBlock() * Constants.DEFAULT_BLOCK_SIZE) + entryOffset;
6467
return readData(startPos, buffer, bufferOffset, len);

loop-fs-iso-impl/src/test/java/com/github/stephenc/javaisotools/loopfs/iso9660/Iso9660FileSystemTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ private void runCheck(Iso9660FileSystem image) throws Exception {
101101
File sourceFile = new File(source, entry.getPath());
102102
assertThat(sourceFile.isDirectory(), is(entry.isDirectory()));
103103
if (!sourceFile.isDirectory()) {
104-
assertThat(sourceFile.length(), is(entry.getSize() * 1L));
104+
assertThat(sourceFile.length(), is(entry.getSize()));
105105
assertThat("contents are equal",
106106
IOUtil.contentEquals(image.getInputStream(entry), new FileInputStream(sourceFile)), is(true));
107107
}

0 commit comments

Comments
 (0)