protected VPackSlice getCurrent() { return new VPackSlice(slice.getBuffer(), (int) current); }
@Override public void close() throws IOException { out.write(builder.slice().getBuffer()); super.close(); } }
@Override public void serialize(final VPackSlice value, final JsonGenerator gen, final SerializerProvider serializers) throws IOException { if (gen instanceof VPackGenerator) { ((VPackGenerator) gen).writeVPack(value); } else { gen.writeBinary(value.getBuffer()); } } };
private HttpRequestBase requestWithBody(final HttpEntityEnclosingRequestBase httpRequest, final Request request) { final VPackSlice body = request.getBody(); if (body != null) { if (contentType == Protocol.HTTP_VPACK) { httpRequest.setEntity(new ByteArrayEntity( Arrays.copyOfRange(body.getBuffer(), body.getStart(), body.getStart() + body.getByteSize()), CONTENT_TYPE_VPACK)); } else { httpRequest.setEntity(new StringEntity(body.toString(), CONTENT_TYPE_APPLICATION_JSON_UTF8)); } } return httpRequest; }
@Override public VPackSlice getValue() { return new VPackSlice(currentField.getBuffer(), currentField.getStart() + currentField.getByteSize()); }
@SuppressWarnings("unchecked") @Override public <T> T deserialize(final VPackSlice vpack, final Type type) throws ArangoDBException { try { final T doc; if (type == String.class && !vpack.isString()) { final JsonNode node = vpackMapper.readTree( Arrays.copyOfRange(vpack.getBuffer(), vpack.getStart(), vpack.getStart() + vpack.getByteSize())); doc = (T) jsonMapper.writeValueAsString(node); } else { doc = vpackMapper.readValue(vpack.getBuffer(), vpack.getStart(), vpack.getStart() + vpack.getByteSize(), (Class<T>) type); } return doc; } catch (final IOException e) { throw new ArangoDBException(e); } }
protected synchronized void writeIntern(final Message message, final Collection<Chunk> chunks) throws ArangoDBException { for (final Chunk chunk : chunks) { try { if (LOGGER.isDebugEnabled()) { LOGGER.debug(String.format("Send chunk %s:%s from message %s", chunk.getChunk(), chunk.isFirstChunk() ? 1 : 0, chunk.getMessageId())); } writeChunkHead(chunk); final int contentOffset = chunk.getContentOffset(); final int contentLength = chunk.getContentLength(); final VPackSlice head = message.getHead(); final int headLength = head.getByteSize(); int written = 0; if (contentOffset < headLength) { written = Math.min(contentLength, headLength - contentOffset); outputStream.write(head.getBuffer(), contentOffset, written); } if (written < contentLength) { final VPackSlice body = message.getBody(); outputStream.write(body.getBuffer(), contentOffset + written - headLength, contentLength - written); } outputStream.flush(); } catch (final IOException e) { throw new ArangoDBException(e); } } }
@Override public byte[] getBinaryValue(final Base64Variant b64variant) throws IOException { if (currentValue.isBinary()) { return currentValue.getAsBinary(); } else if (currentValue.isString()) { return b64variant.decode(currentValue.getAsString()); } return Arrays.copyOfRange(currentValue.getBuffer(), currentValue.getStart(), currentValue.getStart() + currentValue.getByteSize()); }