private static ByteArray acquireReadBuf() { return _dataReadBufs.acquire(); }
public CachingByteArrayOutputStream(int cacheQuantity, int arraySize) { super(0); _cache = ByteCache.getInstance(cacheQuantity, arraySize); _buf = _cache.acquire(); super.buf = _buf.getData(); }
public HTTPResponseOutputStream(OutputStream raw) { super(raw); _context = I2PAppContext.getGlobalContext(); // all createRateStat in I2PTunnelHTTPClient.startRunning() _log = _context.logManager().getLog(getClass()); _headerBuffer = _cache.acquire(); _buf1 = new byte[1]; }
byte[] buf; if (buflen == BUFSIZE) { ba = _cache.acquire(); buf = ba.getData(); } else {
byte[] buf; if (buflen == BUFSIZE) { ba = _cache.acquire(); buf = ba.getData(); } else {
/** * Copy in to out. Caller MUST close the streams. * * @param in non-null * @param out non-null * @since 0.9.29 */ public static void copy(InputStream in, OutputStream out) throws IOException { final ByteCache cache = ByteCache.getInstance(8, 8*1024); final ByteArray ba = cache.acquire(); try { final byte buf[] = ba.getData(); int read; while ((read = in.read(buf)) != -1) { out.write(buf, 0, read); } } finally { cache.release(ba); } }
ByteArray ba = _cache.acquire(); byte[] buf = ba.getData(); try {
byte[] tmp; if (len == BUFSIZE) { ba = _cache.acquire(); tmp = ba.getData(); } else {
/** * Send bytes through the SAM STREAM session socket sender * * @throws IOException if the client didnt provide enough data */ @Override public void sendBytes(InputStream in, int size) throws IOException { if (_log.shouldLog(Log.DEBUG)) _log.debug("Handler " + _id + ": sending " + size + " bytes"); ByteArray ba = _cache.acquire(); int read = DataHelper.read(in, ba.getData(), 0, size); if (read != size) throw new IOException("Insufficient data from the SAM client (" + read + "/" + size + ")"); ba.setValid(read); synchronized (_data) { _data.add(ba); _data.notifyAll(); } }
public void readMessage(byte data[], int offset, int dataSize, int type) throws I2NPMessageException { if (type != MESSAGE_TYPE) throw new I2NPMessageException("Message type is incorrect for this message"); int curIndex = offset; _tunnelId = DataHelper.fromLong(data, curIndex, 4); curIndex += 4; if (_tunnelId <= 0) throw new I2NPMessageException("Invalid tunnel Id " + _tunnelId); // we cant cache it in trivial form, as other components (e.g. HopProcessor) // call getData() and use it as the buffer to write with. it is then used // again to pass to the 'receiver', which may even cache it in a FragmentMessage. if (PIPELINED_CACHE) { _dataBuf = _cache.acquire(); _data = _dataBuf.getData(); _hadCache = true; } else { _data = new byte[DATA_SIZE]; } System.arraycopy(data, curIndex, _data, 0, DATA_SIZE); }
byte preprocessed[] = _dataCache.acquire().getData();
public MessageOutputStream(I2PAppContext ctx, SimpleTimer2 timer, DataReceiver receiver, int bufSize, int passiveFlushDelay) { super(); _dataCache = ByteCache.getInstance(128, bufSize); _originalBufferSize = bufSize; _currentBufferSize = bufSize; _context = ctx; _log = ctx.logManager().getLog(MessageOutputStream.class); _buf = _dataCache.acquire().getData(); // new byte[bufSize]; _dataReceiver = receiver; _dataLock = new Object(); _writeTimeout = -1; _passiveFlushDelay = passiveFlushDelay; _nextBufferSize = 0; //_sendPeriodBeginTime = ctx.clock().now(); //_context.statManager().createRateStat("stream.sendBps", "How fast we pump data through the stream", "Stream", new long[] { 60*1000, 5*60*1000, 60*60*1000 }); _flusher = new Flusher(timer); //if (_log.shouldLog(Log.DEBUG)) // _log.debug("MessageOutputStream created"); }
ByteArray outBuf = cache.acquire(); try { int written = 0;
_log.debug ( "Handler " + _id + ": sending " + size + " bytes" ); ByteArray ba = _cache.acquire();
ByteArray ba = _cache.acquire(); byte[] buffer = ba.getData(); // new byte[NETWORK_BUFFER_SIZE]; try {
/** * Returns a byte array containing a portion of the requested piece or null if * the storage doesn't contain the piece yet. */ public ByteArray getPiece(int piece, int off, int len) throws IOException { if (!bitfield.get(piece)) return null; //Catch a common place for OOMs esp. on 1MB pieces ByteArray rv; byte[] bs; try { // Will be restored to cache in Message.sendMessage() if (len == BUFSIZE) rv = _cache.acquire(); else rv = new ByteArray(new byte[len]); } catch (OutOfMemoryError oom) { if (_log.shouldLog(Log.WARN)) _log.warn("Out of memory, can't honor request for piece " + piece, oom); return null; } bs = rv.getData(); getUncheckedPiece(piece, bs, off, len); return rv; }
ByteArray ba = _cache.acquire(); // new ByteArray(payload, offset, length); // new byte[length]); System.arraycopy(payload, offset, ba.getData(), 0, length); ba.setValid(length);
_log.debug("Receive message " + _messageId + " fragment " + fragmentNum + " with " + length + " bytes (last? " + isLast + ") offset = " + offset); ByteArray ba = _cache.acquire(); //new ByteArray(payload, offset, length); //new byte[length]); System.arraycopy(payload, offset, ba.getData(), 0, length); ba.setValid(length);
ByteArray ba = _validateCache.acquire(); // larger than necessary, but always sufficient byte preV[] = ba.getData(); int validLength = length - offset - paddingEnd + HopProcessor.IV_LENGTH;
ByteArray message = _fragmentCache.acquire(); try { data.readMessageFragment(dataFragment, message.getData(), 0);