public void write(IApimanBuffer chunk) { if (fileOS == null) { try { fileOS = new FileOutputStream(tmpFile); fileOS.write(chunk.getBytes()); } catch (IOException e) { // TODO: Log the error. // The response will not be cached as it might not contain a valid body writeFailed = true; } } }
public void write(IApimanBuffer chunk) { if (fileOS == null) { try { fileOS = new FileOutputStream(tmpFile); fileOS.write(chunk.getBytes()); } catch (IOException e) { // TODO: Log the error. // The response will not be cached as it might not contain a valid body writeFailed = true; } } }
/** * @see io.apiman.gateway.engine.io.IWriteStream#write(io.apiman.gateway.engine.io.IApimanBuffer) */ @Override public void write(IApimanBuffer chunk) { if (this.output == null) { this.output = new ByteArrayOutputStream(); } try { this.output.write(chunk.getBytes()); } catch (IOException e) { // should never happen :) } }
/** * @see io.apiman.gateway.engine.io.IApimanBuffer#append(io.apiman.gateway.engine.io.IApimanBuffer, int, int) */ @Override public void append(IApimanBuffer buffer, int offset, int length) { int sizeToAppend = length; int newBufferSize = this.bytesInBuffer + sizeToAppend; if (this.buffer.length >= newBufferSize) { System.arraycopy(buffer.getBytes(), offset, this.buffer, bytesInBuffer, sizeToAppend); } else { byte [] newBuffer = new byte[newBufferSize]; System.arraycopy(this.buffer, 0, newBuffer, 0, bytesInBuffer); System.arraycopy(buffer.getBytes(), offset, newBuffer, bytesInBuffer, sizeToAppend); this.buffer = newBuffer; } this.bytesInBuffer = newBufferSize; }
/** * @see io.apiman.gateway.engine.io.IWriteStream#write(io.apiman.gateway.engine.io.IApimanBuffer) */ @Override public void write(IApimanBuffer chunk) { if (this.output == null) { this.output = new ByteArrayOutputStream(); } try { this.output.write(chunk.getBytes()); } catch (IOException e) { // should never happen :) } }
/** * @see io.apiman.gateway.engine.io.IApimanBuffer#append(io.apiman.gateway.engine.io.IApimanBuffer, int, int) */ @Override public void append(IApimanBuffer buffer, int offset, int length) { int sizeToAppend = length; int newBufferSize = this.bytesInBuffer + sizeToAppend; if (this.buffer.length >= newBufferSize) { System.arraycopy(buffer.getBytes(), offset, this.buffer, bytesInBuffer, sizeToAppend); } else { byte [] newBuffer = new byte[newBufferSize]; System.arraycopy(this.buffer, 0, newBuffer, 0, bytesInBuffer); System.arraycopy(buffer.getBytes(), offset, newBuffer, bytesInBuffer, sizeToAppend); this.buffer = newBuffer; } this.bytesInBuffer = newBufferSize; }
/** * Return the rest of the buffer (everything after the soap headers); * @param buffer */ public byte[] getRemainingBytes() { return this.buffer.getBytes(headers.endIdx + 1, buffer.length()); }
/** * @see io.apiman.gateway.engine.components.IBufferFactoryComponent#cloneBuffer(io.apiman.gateway.engine.io.IApimanBuffer) */ @Override public IApimanBuffer cloneBuffer(IApimanBuffer buffer) { return new ByteBuffer(buffer.getBytes()); } }
/** * Return the rest of the buffer (everything after the soap headers); * @param buffer */ public byte[] getRemainingBytes() { return this.buffer.getBytes(headers.endIdx + 1, buffer.length()); }
/** * @see io.apiman.gateway.engine.components.IBufferFactoryComponent#cloneBuffer(io.apiman.gateway.engine.io.IApimanBuffer) */ @Override public IApimanBuffer cloneBuffer(IApimanBuffer buffer) { return new ByteBuffer(buffer.getBytes()); } }
private Buffer getNativeBuffer(IApimanBuffer buffer) { if (buffer.getNativeBuffer() instanceof Buffer) { return (Buffer) buffer.getNativeBuffer(); } else { logger.debug("Received an IApimanBuffer with a non-Vert.x implementation. " //$NON-NLS-1$ + "This will function but may require copying and be less efficient."); //$NON-NLS-1$ return Buffer.buffer(buffer.getBytes()); } } }
/** * @see io.apiman.gateway.engine.io.IWriteStream#write(io.apiman.gateway.engine.io.IApimanBuffer) */ @Override public void write(IApimanBuffer chunk) { try { if (!connected) { throw new IOException("Not connected."); //$NON-NLS-1$ } if (outputStream == null) { outputStream = connection.getOutputStream(); } if (chunk instanceof ByteBuffer) { byte[] buffer = (byte[]) chunk.getNativeBuffer(); outputStream.write(buffer, 0, chunk.length()); } else { outputStream.write(chunk.getBytes()); } } catch (IOException e) { handleConnectionError(e); } }
/** * @see io.apiman.gateway.engine.io.IWriteStream#write(io.apiman.gateway.engine.io.IApimanBuffer) */ @Override public void write(IApimanBuffer chunk) { try { if (!connected) { throw new IOException("Not connected."); //$NON-NLS-1$ } if (outputStream == null) { outputStream = connection.getOutputStream(); } if (chunk instanceof ByteBuffer) { byte[] buffer = (byte[]) chunk.getNativeBuffer(); outputStream.write(buffer, 0, chunk.length()); } else { outputStream.write(chunk.getBytes()); } } catch (IOException e) { handleConnectionError(e); } }
@Override public void end() { if (!aborted) { synchronized (mutex) { InfinispanCacheEntry entry = (InfinispanCacheEntry) getCache().get(cacheKey); if (entry == null) { entry = new InfinispanCacheEntry(); } entry.setHead(jsonObject); entry.setExpiresOn(System.currentTimeMillis() + (timeToLive * 1000)); entry.setData(dataBuffer.getBytes()); getCache().put(cacheKey, entry); } } } };
@Override public void end() { if (!aborted) { synchronized (mutex) { InfinispanCacheEntry entry = (InfinispanCacheEntry) getCache().get(cacheKey); if (entry == null) { entry = new InfinispanCacheEntry(); } entry.setHead(jsonObject); entry.setExpiresOn(System.currentTimeMillis() + (timeToLive * 1000)); entry.setData(dataBuffer.getBytes()); getCache().put(cacheKey, entry); } } } };
@Override public void end() { if (!aborted) { entry.setData(Base64.encodeBase64String(data.getBytes())); Index index = new Index.Builder(entry).refresh(false).index(getIndexName()) .type("cacheEntry").id(cacheKey).build(); //$NON-NLS-1$ try { getClient().execute(index); } catch (Throwable e) { } } finished = true; } };
@Override public void end() { if (!aborted) { entry.setData(Base64.encodeBase64String(data.getBytes())); Index index = new Index.Builder(entry).refresh(false).index(getIndexName()) .type("cacheEntry").id(cacheKey).build(); //$NON-NLS-1$ try { getClient().execute(index); } catch (Throwable e) { } } finished = true; } };
IApimanBuffer preUrlData = bufferFactory.createBuffer(originalBuffer.getBytes(preUrlFromPos, position)); super.write(preUrlData); bytesConsumed = position; urlBuffer = bufferFactory.createBuffer(url, "UTF-8"); //$NON-NLS-1$ } else { urlBuffer = bufferFactory.createBuffer(originalBuffer.getBytes(originalPos, position)); buffer = null; } else { buffer = bufferFactory.createBuffer(originalBuffer.getBytes(bytesConsumed, maxPos + 1)); if (atEnd) { super.write(buffer);