-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
change logic to use streams for package data attributes instead of lo…
…ading into ram
- Loading branch information
Showing
8 changed files
with
156 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
haikudepotserver-packagefile/src/main/java/org/haiku/pkg/heap/HeapInputStream.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Copyright 2021, Andrew Lindesay | ||
* Distributed under the terms of the MIT License. | ||
*/ | ||
|
||
package org.haiku.pkg.heap; | ||
|
||
import com.google.common.base.Preconditions; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class HeapInputStream extends InputStream { | ||
|
||
private final HeapReader reader; | ||
|
||
private final HeapCoordinates coordinates; | ||
|
||
private long offsetInCoordinates = 0L; | ||
|
||
public HeapInputStream(HeapReader reader, HeapCoordinates coordinates) { | ||
this.reader = Preconditions.checkNotNull(reader); | ||
this.coordinates = Preconditions.checkNotNull(coordinates); | ||
} | ||
|
||
@Override | ||
public int read() throws IOException { | ||
if (offsetInCoordinates < coordinates.getLength()) { | ||
int result = reader.readHeap(coordinates.getOffset() + offsetInCoordinates); | ||
offsetInCoordinates++; | ||
return result; | ||
} | ||
|
||
return -1; | ||
} | ||
|
||
@Override | ||
public int read(byte[] b, int off, int len) throws IOException { | ||
Preconditions.checkArgument(null != b, "buffer required"); | ||
Preconditions.checkArgument(off >= 0, "bad offset supplied"); | ||
Preconditions.checkArgument(len >= 0, "bad length supplied"); | ||
|
||
if (len + offsetInCoordinates >= coordinates.getLength()) { | ||
len = (int) (coordinates.getLength() - offsetInCoordinates); | ||
} | ||
|
||
if (0 == len) { | ||
return -1; | ||
} | ||
|
||
HeapCoordinates readCoordinates = new HeapCoordinates( | ||
coordinates.getOffset() + offsetInCoordinates, len); | ||
|
||
reader.readHeap(b, off, readCoordinates); | ||
offsetInCoordinates += len; | ||
|
||
return len; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters