Skip to content

Instantly share code, notes, and snippets.

View conorgriffin's full-sized avatar

Conor Griffin conorgriffin

View GitHub Profile
@conorgriffin
conorgriffin / Test-Results.txt
Created February 22, 2021 16:27
Test Results
latency: 0ms
------------------
64 reads: 32683ms
32 reads: 35815ms
16 reads: 35298ms
8 reads: 38902ms
latency: 20ms
------------------
64 reads: 42407ms
@conorgriffin
conorgriffin / SftpOperations.scala
Last active February 22, 2021 16:24
SftpOperations - Multiple Read Requests
def retrieveFileInputStream(name: String,
handler: Handler,
offset: Long,
maxUnconfirmedReads: Int): Try[InputStream] =
Try {
val remoteFile = handler.open(name, java.util.EnumSet.of(OpenMode.READ))
val is = maxUnconfirmedReads match {
case m if m > 1 =>
new remoteFile.ReadAheadRemoteFileInputStream(m, offset) {
@conorgriffin
conorgriffin / SftpOperations.scala
Created February 22, 2021 15:02
SftpOperations - Alpakka Single Read Request
def retrieveFileInputStream(name: String, handler: Handler, offset: Long): Try[InputStream] =
Try {
val remoteFile = handler.open(name, java.util.EnumSet.of(OpenMode.READ))
val is = new remoteFile.RemoteFileInputStream(offset) {
override def close(): Unit =
try {
super.close()
} finally {
remoteFile.close()
@conorgriffin
conorgriffin / SFTPFileTransfer.java
Created February 22, 2021 14:58
SSHJ's SFTPFileTransfer
private LocalDestFile downloadFile(final StreamCopier.Listener listener,
final RemoteResourceInfo remote,
final LocalDestFile local)
throws IOException {
final LocalDestFile adjusted = local.getTargetFile(remote.getName());
final RemoteFile rf = engine.open(remote.getPath());
try {
final RemoteFile.ReadAheadRemoteFileInputStream rfis = rf.new ReadAheadRemoteFileInputStream(16);
final OutputStream os = adjusted.getOutputStream();
try {
@conorgriffin
conorgriffin / FtpIOGraphStage.scala
Created February 22, 2021 14:51
FtpIOGraphStage - Multiple Read Requests
protected[this] def doPreStart(): Unit =
isOpt = ftpLike match {
case ur: UnconfirmedReads =>
withUnconfirmedReads(ur)
case ro: RetrieveOffset =>
Some(ro.retrieveFileInputStream(path, handler.get.asInstanceOf[ro.Handler], offset).get)
case _ =>
Some(ftpLike.retrieveFileInputStream(path, handler.get).get)
}
@conorgriffin
conorgriffin / FtpIOGraphStage.scala
Created February 22, 2021 14:49
FtpIOGraphStage - Single Read Request
protected[this] def doPreStart(): Unit =
isOpt = ftpLike match {
case ro: RetrieveOffset =>
Some(ro.retrieveFileInputStream(path, handler.get.asInstanceOf[ro.Handler], offset).get)
case _ =>
Some(ftpLike.retrieveFileInputStream(path, handler.get).get)
}
@conorgriffin
conorgriffin / Deflater.c
Created December 18, 2019 22:51
Native method
Java_java_util_zip_Deflater_init(JNIEnv *env, jclass cls, jint level,
jint strategy, jboolean nowrap)
{
z_stream *strm = calloc(1, sizeof(z_stream));
if (strm == 0) {
JNU_ThrowOutOfMemoryError(env, 0);
return jlong_zero;
} else {
char *msg;
@conorgriffin
conorgriffin / GZIPOutputStream.java
Created December 18, 2019 16:30
Alternative solution is to copy what GZIPOutputStream does
public GZIPOutputStream(OutputStream out, int size, boolean syncFlush)
throws IOException
{
super(out, new Deflater(Deflater.DEFAULT_COMPRESSION, true),
size,
syncFlush);
usesDefaultDeflater = true;
writeHeader();
crc.reset();
}
@conorgriffin
conorgriffin / Fix.java
Last active August 17, 2020 20:45
The Fix
outputStream = new DeflaterOutputStream(outputStream, new Deflater(), BLOCK_SIZE) {
@Override
public void close() throws IOException {
try {
super.close();
} finally {
def.end();
}
}
};
@conorgriffin
conorgriffin / Bug.java
Created December 18, 2019 16:21
The Bug
outputStream = new DeflaterOutputStream(outputStream, new Deflater(), BLOCK_SIZE);