Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Attempt to bump TRL or trig reader from 4 (works under laboratory con…
…ditions) to 6/7 (works in a relevant setup)... Seems to work for decompressed data so far.
- Loading branch information
Showing
6 changed files
with
468 additions
and
116 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
69 changes: 69 additions & 0 deletions
69
...-rdf-common/src/main/java/net/sansa_stack/rdf/common/InterruptingReadableByteChannel.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,69 @@ | ||
package net.sansa_stack.rdf.common; | ||
|
||
import com.google.common.primitives.Ints; | ||
import org.apache.hadoop.fs.Seekable; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.ByteBuffer; | ||
import java.nio.channels.ReadableByteChannel; | ||
|
||
/** ReadabalByteChannel whose read method is guaranteed to return at a specific position | ||
* (before crossing it) such as a split boundary | ||
*/ | ||
public class InterruptingReadableByteChannel | ||
implements ReadableByteChannel, SeekableBase | ||
{ | ||
protected byte[] buffer = new byte[1024 * 1024]; | ||
protected boolean interrupted = false; | ||
protected InputStream in; | ||
protected Seekable seekable; | ||
protected long interruptPos; | ||
|
||
public InterruptingReadableByteChannel( | ||
InputStream in, | ||
Seekable seekable, | ||
long interruptPos) { | ||
this.in = in; | ||
this.seekable = seekable; | ||
this.interruptPos = interruptPos; | ||
} | ||
|
||
@Override | ||
public int read(ByteBuffer byteBuffer) throws IOException { | ||
long pos = seekable.getPos(); | ||
int remainingUntilInterrupt = !interrupted && pos <= interruptPos | ||
? Ints.saturatedCast(interruptPos - pos) | ||
: Integer.MAX_VALUE; | ||
|
||
int toRead = Math.min(byteBuffer.remaining(), remainingUntilInterrupt); | ||
toRead = Math.min(toRead, buffer.length); | ||
|
||
int contrib = in.read(buffer, 0, toRead); | ||
|
||
if (contrib >= 0) { | ||
byteBuffer.put(buffer, 0, contrib); | ||
} | ||
|
||
if (pos == interruptPos) { | ||
interrupted = true; | ||
} | ||
|
||
return contrib; | ||
} | ||
|
||
@Override | ||
public boolean isOpen() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void close() throws IOException { | ||
in.close(); | ||
} | ||
|
||
@Override | ||
public Seekable getSeekable() { | ||
return seekable; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
sansa-rdf/sansa-rdf-common/src/main/java/net/sansa_stack/rdf/common/SeekableBase.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,26 @@ | ||
package net.sansa_stack.rdf.common; | ||
|
||
import org.apache.hadoop.fs.Seekable; | ||
|
||
import java.io.IOException; | ||
|
||
public interface SeekableBase | ||
extends Seekable | ||
{ | ||
Seekable getSeekable(); | ||
|
||
@Override | ||
default void seek(long l) throws IOException { | ||
getSeekable().seek(l); | ||
} | ||
|
||
@Override | ||
default long getPos() throws IOException { | ||
return getSeekable().getPos(); | ||
} | ||
|
||
@Override | ||
default boolean seekToNewSource(long l) throws IOException { | ||
return getSeekable().seekToNewSource(l); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
sansa-rdf/sansa-rdf-common/src/main/java/net/sansa_stack/rdf/common/SeekableInputStream.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,28 @@ | ||
package net.sansa_stack.rdf.common; | ||
|
||
import org.apache.commons.io.input.ProxyInputStream; | ||
import org.apache.hadoop.fs.Seekable; | ||
|
||
import java.io.InputStream; | ||
|
||
/** Combine Seekable and InputStream into one class */ | ||
public class SeekableInputStream | ||
extends ProxyInputStream implements SeekableBase | ||
{ | ||
protected Seekable seekable; | ||
|
||
/** | ||
* Constructs a new ProxyInputStream. | ||
* | ||
* @param proxy the InputStream to delegate to | ||
*/ | ||
public SeekableInputStream(InputStream proxy, Seekable seekable) { | ||
super(proxy); | ||
this.seekable = seekable; | ||
} | ||
|
||
@Override | ||
public Seekable getSeekable() { | ||
return seekable; | ||
} | ||
} |
Oops, something went wrong.