Refine search
@Override public void writeTo(final Object t, final Class type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap httpHeaders, final OutputStream entityStream) throws IOException, WebApplicationException { entityStream.write(t.toString().getBytes(MessageUtils.getCharset(mediaType))); }
entityStream.write(builder.toString().getBytes(MessageUtils.getCharset(mediaType))); entityStream.flush();
@Override public void writeTo(final Set<String> s, final Class<?> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, Object> httpHeaders, final OutputStream entityStream) throws IOException, WebApplicationException { final PrintStream ps = new PrintStream(entityStream, true, MessageUtils.getCharset(mediaType).name()); for (final String item : s) { ps.println(item); } } }
entityStream.write(builder.toString().getBytes(MessageUtils.getCharset(mediaType))); entityStream.flush();
@Override public Object readFrom(final Class type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap httpHeaders, final InputStream entityStream) throws IOException, WebApplicationException { return new ClipboardData(readStringFromStream(entityStream, MessageUtils.getCharset(mediaType))); } }
@Override public void writeTo(final Object t, final Class type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap httpHeaders, final OutputStream entityStream) throws IOException, WebApplicationException { entityStream.write(String.format("%s%s%s", JsonOpenning, t.toString(), JsonClosing) .getBytes(MessageUtils.getCharset(mediaType))); }
@Override public Set<String> readFrom(final Class<Set<String>> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, String> httpHeaders, final InputStream entityStream) throws IOException, WebApplicationException { final BufferedReader br = new BufferedReader(new InputStreamReader(entityStream, MessageUtils.getCharset(mediaType))); final Set<String> result = new HashSet<>(); String line; while ((line = br.readLine()) != null) { result.add(line); } return result; } }
@Override public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException { final boolean isJavascript = isJavascript(context.getMediaType()); final JSONP jsonp = getJsonpAnnotation(context); final boolean wrapIntoCallback = isJavascript && jsonp != null; if (wrapIntoCallback) { context.setMediaType(MediaType.APPLICATION_JSON_TYPE); context.getOutputStream().write(getCallbackName(jsonp).getBytes(MessageUtils.getCharset(context.getMediaType()))); context.getOutputStream().write('('); } context.proceed(); if (wrapIntoCallback) { context.getOutputStream().write(')'); } }
@Override public Object readFrom(final Class type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap httpHeaders, final InputStream entityStream) throws IOException, WebApplicationException { final String jsonExpression = readStringFromStream(entityStream, MessageUtils.getCharset(mediaType)); return new ClipboardData(jsonExpression.replace(JsonOpenning, "").replace(JsonClosing, "")); } }
@Override public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException { final boolean isJavascript = isJavascript(context.getMediaType()); final JSONP jsonp = getJsonpAnnotation(context); final boolean wrapIntoCallback = isJavascript && jsonp != null; if (wrapIntoCallback) { context.setMediaType(MediaType.APPLICATION_JSON_TYPE); context.getOutputStream().write(getCallbackName(jsonp).getBytes(MessageUtils.getCharset(context.getMediaType()))); context.getOutputStream().write('('); } context.proceed(); if (wrapIntoCallback) { context.getOutputStream().write(')'); } }
@Override public Reader readFrom( final Class<Reader> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, String> httpHeaders, final InputStream inputStream) throws IOException { final EntityInputStream entityStream = EntityInputStream.create(inputStream); if (entityStream.isEmpty()) { return new BufferedReader(new InputStreamReader( new ByteArrayInputStream(new byte[0]), MessageUtils.getCharset(mediaType))); } return new BufferedReader(new InputStreamReader(entityStream, getCharset(mediaType))); }
final OutputStream entityStream) throws IOException, WebApplicationException { final Charset charset = MessageUtils.getCharset(mediaType); if (outboundEvent.getComment() != null) { for (final String comment : outboundEvent.getComment().split("\n")) { entityStream.write(COMMENT_LEAD); entityStream.write(comment.getBytes(charset)); entityStream.write(EOL);
@Override public Reader readFrom( final Class<Reader> type, final Type genericType, final Annotation[] annotations, final MediaType mediaType, final MultivaluedMap<String, String> httpHeaders, final InputStream inputStream) throws IOException { final EntityInputStream entityStream = EntityInputStream.create(inputStream); if (entityStream.isEmpty()) { return new BufferedReader(new InputStreamReader( new ByteArrayInputStream(new byte[0]), MessageUtils.getCharset(mediaType))); } return new BufferedReader(new InputStreamReader(entityStream, getCharset(mediaType))); }
@Override public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException { final boolean isJavascript = isJavascript(context.getMediaType()); final JSONP jsonp = getJsonpAnnotation(context); final boolean wrapIntoCallback = isJavascript && jsonp != null; if (wrapIntoCallback) { context.setMediaType(MediaType.APPLICATION_JSON_TYPE); context.getOutputStream().write(getCallbackName(jsonp).getBytes(MessageUtils.getCharset(context.getMediaType()))); context.getOutputStream().write('('); } context.proceed(); if (wrapIntoCallback) { context.getOutputStream().write(')'); } }
private enum State { SKIPPING_PREPENDED_EMPTY_EVENTS, NEW_LINE, COMMENT, FIELD, }
@Override public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException { final boolean isJavascript = isJavascript(context.getMediaType()); final JSONP jsonp = getJsonpAnnotation(context); final boolean wrapIntoCallback = isJavascript && jsonp != null; if (wrapIntoCallback) { context.setMediaType(MediaType.APPLICATION_JSON_TYPE); context.getOutputStream().write(getCallbackName(jsonp).getBytes(MessageUtils.getCharset(context.getMediaType()))); context.getOutputStream().write('('); } context.proceed(); if (wrapIntoCallback) { context.getOutputStream().write(')'); } }
private void processField(final InboundEvent.Builder inboundEventBuilder, final String name, final MediaType mediaType, final byte[] value) { final String valueString = new String(value, MessageUtils.getCharset(mediaType)); if ("event".equals(name)) { inboundEventBuilder.name(valueString); } else if ("data".equals(name)) { inboundEventBuilder.write(value); inboundEventBuilder.write(EOL_DATA); } else if ("id".equals(name)) { inboundEventBuilder.id(valueString); } else if ("retry".equals(name)) { try { inboundEventBuilder.reconnectDelay(Long.parseLong(valueString)); } catch (final NumberFormatException ex) { LOGGER.log(Level.FINE, LocalizationMessages.IN_EVENT_RETRY_PARSE_ERROR(valueString), ex); } } else { LOGGER.fine(LocalizationMessages.IN_EVENT_FIELD_NOT_RECOGNIZED(name, valueString)); } } }
@Override public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException { final boolean isJavascript = isJavascript(context.getMediaType()); final JSONP jsonp = getJsonpAnnotation(context); final boolean wrapIntoCallback = isJavascript && jsonp != null; if (wrapIntoCallback) { context.setMediaType(MediaType.APPLICATION_JSON_TYPE); context.getOutputStream().write(getCallbackName(jsonp).getBytes(MessageUtils.getCharset(context.getMediaType()))); context.getOutputStream().write('('); } context.proceed(); if (wrapIntoCallback) { context.getOutputStream().write(')'); } }
@Override public void aroundWriteTo(final WriterInterceptorContext writerInterceptorContext) throws IOException, WebApplicationException { final LoggingStream stream = (LoggingStream) writerInterceptorContext.getProperty(ENTITY_LOGGER_PROPERTY); writerInterceptorContext.proceed(); if (logger.isLoggable(level) && printEntity(verbosity, writerInterceptorContext.getMediaType())) { if (stream != null) { log(stream.getStringBuilder(MessageUtils.getCharset(writerInterceptorContext.getMediaType()))); } } }
@Override public void aroundWriteTo(final WriterInterceptorContext context) throws IOException, WebApplicationException { final boolean isJavascript = isJavascript(context.getMediaType()); final JSONP jsonp = getJsonpAnnotation(context); final boolean wrapIntoCallback = isJavascript && jsonp != null; if (wrapIntoCallback) { context.setMediaType(MediaType.APPLICATION_JSON_TYPE); context.getOutputStream().write(getCallbackName(jsonp).getBytes(MessageUtils.getCharset(context.getMediaType()))); context.getOutputStream().write('('); } context.proceed(); if (wrapIntoCallback) { context.getOutputStream().write(')'); } }