@Override public void write(IApimanBuffer chunk) { total += chunk.length(); super.write(chunk); } @Override
@Override public void write(IApimanBuffer chunk) { total += chunk.length(); super.write(chunk); } @Override
/** * 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.io.IApimanBuffer#append(io.apiman.gateway.engine.io.IApimanBuffer) */ @Override public void append(IApimanBuffer buffer) { append(buffer, 0, buffer.length()); }
@Override public void end() { finished = true; synchronized (cacheSizeMutex) { cacheSize += buffer.length(); if (cacheSize > maxCacheSize) { synchronized (mapMutex) { while (cacheSize > maxCacheSize) { String cacheKey = objectCache.keySet().iterator().next(); objectCache.remove(cacheKey); expireOnMap.remove(cacheKey); IApimanBuffer removedBuffer = dataCache.remove(cacheKey); if (removedBuffer != null) { cacheSize -= removedBuffer.length(); } } } } } } };
/** * 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.io.IApimanBuffer#append(io.apiman.gateway.engine.io.IApimanBuffer) */ @Override public void append(IApimanBuffer buffer) { append(buffer, 0, buffer.length()); }
@Override public void end() { finished = true; synchronized (cacheSizeMutex) { cacheSize += buffer.length(); if (cacheSize > maxCacheSize) { synchronized (mapMutex) { while (cacheSize > maxCacheSize) { String cacheKey = objectCache.keySet().iterator().next(); objectCache.remove(cacheKey); expireOnMap.remove(cacheKey); IApimanBuffer removedBuffer = dataCache.remove(cacheKey); if (removedBuffer != null) { cacheSize -= removedBuffer.length(); } } } } } } };
/** * Search for the given character in the buffer, starting at the * given index. If not found, return -1. If found, return the * index of the character. * @param c * @param index */ private int findFrom(char c, int index) { int currentIdx = index; while (currentIdx < buffer.length()) { if (buffer.get(currentIdx) == c) { return currentIdx; } currentIdx++; } return -1; }
/** * Search for the given character in the buffer, starting at the * given index. If not found, return -1. If found, return the * index of the character. * @param c * @param index */ private int findFrom(char c, int index) { int currentIdx = index; while (currentIdx < buffer.length()) { if (buffer.get(currentIdx) == c) { return currentIdx; } currentIdx++; } return -1; }
/** * @return the URL consumed from the buffer */ private String consumeURL() { String rval = null; int pos = position + "http://".length(); //$NON-NLS-1$ while (pos < buffer.length() && isValidURLChar(pos)) { pos++; } if (pos < buffer.length() || atEnd) { try { rval = buffer.getString(position, pos, "UTF-8"); //$NON-NLS-1$ } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } position = pos; } return rval; }
public VertxApimanBuffer(IApimanBuffer buffer) { this.nativeBuffer = Buffer.buffer(buffer.length()).appendBuffer((Buffer) buffer.getNativeBuffer()); }
/** * @param index */ private int consumeEnvelopeDecl(int index) { int end = findFrom('>', index); if (end == -1) { // Not enough buffer - need more data. return buffer.length(); } try { String str = buffer.getString(index, end + 1, "UTF-8"); //$NON-NLS-1$ String [] split = str.split(" "); //$NON-NLS-1$ if (split[0].endsWith("Envelope")) { //$NON-NLS-1$ envelopeDecl.startIdx = index; envelopeDecl.endIdx = end; return end + 1; } } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } // We found a section of XML that should have been a soap:Envelope, but wasn't. return -1; }
/** * @param index */ private int consumeEnvelopeDecl(int index) { int end = findFrom('>', index); if (end == -1) { // Not enough buffer - need more data. return buffer.length(); } try { String str = buffer.getString(index, end + 1, "UTF-8"); //$NON-NLS-1$ String [] split = str.split(" "); //$NON-NLS-1$ if (split[0].endsWith("Envelope")) { //$NON-NLS-1$ envelopeDecl.startIdx = index; envelopeDecl.endIdx = end; return end + 1; } } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } // We found a section of XML that should have been a soap:Envelope, but wasn't. return -1; }
/** * @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); } }
/** * Append the given data to any existing buffer, then scan the buffer * looking for the soap headers. If scanning is complete, this method * will return true. If more data is required, then the method will return * false. If an error condition is detected, then an exception will be * thrown. * @param buffer */ public boolean scan(IApimanBuffer buffer) throws SoapEnvelopeNotFoundException { if (this.buffer == null) { this.buffer = buffer; } else { this.buffer.append(buffer); } boolean scanComplete = doScan(); // If our buffer is already "max size" but we haven't found the start of the // soap envelope yet, then we're likely not going to find it. if (!scanComplete && this.buffer.length() >= getMaxBufferLength()) { throw new SoapEnvelopeNotFoundException(); } return scanComplete; }
/** * Append the given data to any existing buffer, then scan the buffer * looking for the soap headers. If scanning is complete, this method * will return true. If more data is required, then the method will return * false. If an error condition is detected, then an exception will be * thrown. * @param buffer */ public boolean scan(IApimanBuffer buffer) throws SoapEnvelopeNotFoundException { if (this.buffer == null) { this.buffer = buffer; } else { this.buffer.append(buffer); } boolean scanComplete = doScan(); // If our buffer is already "max size" but we haven't found the start of the // soap envelope yet, then we're likely not going to find it. if (!scanComplete && this.buffer.length() >= getMaxBufferLength()) { throw new SoapEnvelopeNotFoundException(); } return scanComplete; }
/** * Returns true if the index points to an XML preamble of the following example form: * * <pre> * <?xml version="1.0"?> * </pre> * @param index */ private boolean isPreamble(int index) { if (index <= buffer.length() - 6) { if ( buffer.get(index) == '<' && buffer.get(index + 1) == '?' && buffer.get(index + 2) == 'x' && buffer.get(index + 3) == 'm' && buffer.get(index + 4) == 'l' && buffer.get(index + 5) == ' ' ) { return true; } } return false; }
/** * Returns true if the index points to an XML preamble of the following example form: * * <pre> * <?xml version="1.0"?> * </pre> * @param index */ private boolean isPreamble(int index) { if (index <= buffer.length() - 6) { if ( buffer.get(index) == '<' && buffer.get(index + 1) == '?' && buffer.get(index + 2) == 'x' && buffer.get(index + 3) == 'm' && buffer.get(index + 4) == 'l' && buffer.get(index + 5) == ' ' ) { return true; } } return false; }