public void close() throws IOException { g.writeEndArray(); g.close(); }
@SuppressWarnings( "unchecked" ) private static List<Object> readArray( JsonParser input ) throws IOException { return input.readValueAs( List.class ); }
public StreamingBatchOperationResults( JsonGenerator g, ServletOutputStream output ) throws IOException { this.g = g; this.output = output; g.writeStartArray(); }
private String readBody( JsonParser jp ) throws IOException { JsonNode node = mapper.readTree( jp ); StringWriter out = new StringWriter(); JsonGenerator gen = jsonFactory .createJsonGenerator(out); mapper.writeTree( gen, node ); gen.flush(); gen.close(); return out.toString(); }
public void startOperation( String from, Integer id ) throws IOException { bytesWritten = 0; g.writeStartObject(); if ( id != null ) { g.writeNumberField( "id", id ); } g.writeStringField( "from", from ); g.writeRaw( ",\"body\":" ); g.flush(); }
private void writeColumns( Iterable<String> columns ) throws IOException { try { out.writeArrayFieldStart( "columns" ); for ( String key : columns ) { out.writeString( key ); } } finally { out.writeEndArray(); // </columns> } }
private void writeByteArray( JsonGenerator out, byte[] bytes ) throws IOException { out.writeStartArray(); try { for ( byte b : bytes ) { out.writeNumber( (int) b ); } } finally { out.writeEndArray(); } }
@Override public Date deserialize(JsonParser parser, DeserializationContext context) throws IOException, JsonProcessingException { try { synchronized (dateFormat) { return dateFormat.parse(parser.getText()); } } catch (ParseException e) { throw new JsonParseException("Could not parse date", parser.getCurrentLocation(), e); } }
private void ensureDocumentOpen() throws IOException { if ( currentState == State.EMPTY ) { out.writeStartObject(); currentState = State.DOCUMENT_OPEN; } }
public StreamingRepresentationFormat usePrettyPrinter() { g.useDefaultPrettyPrinter(); return this; }
/** * Helper method for constructing {@link JsonParseException}s * based on current state of the parser */ protected JsonParseException _constructError(String msg) { return new JsonParseException(msg, getCurrentLocation()); } }
/** * Similar to {@link #writeBinary(Base64Variant,byte[],int,int)}, * but default to using the Jackson default Base64 variant * (which is {@link Base64Variants#MIME_NO_LINEFEEDS}). */ public void writeBinary(byte[] data, int offset, int len) throws IOException, JsonGenerationException { writeBinary(Base64Variants.getDefaultVariant(), data, offset, len); }
/** * Convenience alternative to {@link #getBinaryValue(Base64Variant)} * that defaults to using * {@link Base64Variants#getDefaultVariant} as the default encoding. */ public byte[] getBinaryValue() throws IOException, JsonParseException { return getBinaryValue(Base64Variants.getDefaultVariant()); }
private void markDeleted( JsonGenerator out ) throws IOException { out.writeBooleanField( "deleted", Boolean.TRUE ); }
/** * Hmmh. This is not quite as efficient as using {@link #serialize}, * but will work correctly. */ @Override public String asText() { return Base64Variants.getDefaultVariant().encode(_data, false); }
/** * Similar to {@link #writeBinary(Base64Variant,byte[],int,int)}, * but assumes default to using the Jackson default Base64 variant * (which is {@link Base64Variants#MIME_NO_LINEFEEDS}). Also * assumes that whole byte array is to be output. */ public void writeBinary(byte[] data) throws IOException, JsonGenerationException { writeBinary(Base64Variants.getDefaultVariant(), data, 0, data.length); }
private void discardValue( JsonParser input ) throws IOException { // This could be done without building up an object input.readValueAs( Object.class ); }
/** * Different from other values, since contents need to be surrounded * by (double) quotes. */ @Override public String toString() { return Base64Variants.getDefaultVariant().encode(_data, true); } }
@SuppressWarnings( "unchecked" ) private static Map<String, Object> readMap( JsonParser input ) throws IOException { return input.readValueAs( Map.class ); }