Util: New zero-copy BAOS

WIP, to be hooked in
This commit is contained in:
zzz
2020-11-02 12:12:20 +00:00
parent 057eca56d5
commit f69563da75
3 changed files with 64 additions and 1 deletions

View File

@ -0,0 +1,52 @@
package net.i2p.util;
import java.io.ByteArrayOutputStream;
import java.io.ByteArrayInputStream;
import java.util.Arrays;
/**
* OutputStream to InputStream adapter.
* Zero-copy where possible. Unsynchronized.
* This is NOT a Pipe.
* Do NOT reset after writing.
*
* @since 0.9.48
*/
public class ByteArrayStream extends ByteArrayOutputStream {
public ByteArrayStream() {
super();
}
public ByteArrayStream(int size) {
super(size);
}
/**
* @throws IllegalStateException if previously written
*/
@Override
public void reset() {
if (count > 0)
throw new IllegalStateException();
}
/**
* Zero-copy only if the data fills the buffer.
* Use asInputStream() for guaranteed zero-copy.
*/
@Override
public byte[] toByteArray() {
if (count == buf.length)
return buf;
return Arrays.copyOfRange(buf, 0, count);
}
/**
* All data previously written. Zero-copy. Not a Pipe.
* Data written after this call will not appear.
*/
public ByteArrayInputStream asInputStream() {
return new ByteArrayInputStream(buf, 0, count);
}
}

View File

@ -1,4 +1,15 @@
2020-11-02 zzz
* I2CP: Remove tunnels immediately on client disconnect
* i2psnark: Limit max size of embedded video
* i2ptunnel: Restart tunnel if offline-signed private key file updated
2020-10-30 zzz
* i2psnark: MetaInfo support for url-list (prep for BEP 19)
* Util: Fix NPE in EepGet CLI callback via PartialEepGet
2020-10-29 zzz 2020-10-29 zzz
* Crypto: Precalculate Noise initial hashes
* i2psnark: Store BEP 47 padding file info
* Tunnels: Improved logging and handling of offline signature expiration * Tunnels: Improved logging and handling of offline signature expiration
2020-10-28 zzz 2020-10-28 zzz

View File

@ -18,7 +18,7 @@ public class RouterVersion {
/** deprecated */ /** deprecated */
public final static String ID = "Monotone"; public final static String ID = "Monotone";
public final static String VERSION = CoreVersion.VERSION; public final static String VERSION = CoreVersion.VERSION;
public final static long BUILD = 11; public final static long BUILD = 12;
/** for example "-test" */ /** for example "-test" */
public final static String EXTRA = ""; public final static String EXTRA = "";