public void writeTo(T obj, Class<?> type, Type genType, Annotation[] anns, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { String encoding = HttpUtils.getSetEncoding(mt, headers, StandardCharsets.UTF_8.name()); byte[] bytes = obj.toString().getBytes(encoding); os.write(bytes); }
public void writeTo(T obj, Class<?> type, Type genType, Annotation[] anns, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { String encoding = HttpUtils.getSetEncoding(mt, headers, "UTF-8"); os.write(obj.toString().getBytes(encoding)); }
@Override public void writeTo(String obj, Class<?> type, Type genType, Annotation[] anns, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { String encoding = HttpUtils.getSetEncoding(mt, headers, "UTF-8"); // REVISIT try to avoid instantiating the whole byte array byte[] bytes = obj.getBytes(encoding); if (bytes.length > this.bufferSize) { int pos = 0; while (pos < bytes.length) { int bl = bytes.length - pos; if (bl > this.bufferSize) { bl = this.bufferSize; } os.write(bytes, pos, bl); pos += bl; } } else { os.write(bytes); } }
@Override public void writeTo(String obj, Class<?> type, Type genType, Annotation[] anns, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { String encoding = HttpUtils.getSetEncoding(mt, headers, "UTF-8"); // REVISIT try to avoid instantiating the whole byte array byte[] bytes = obj.getBytes(encoding); if (bytes.length > this.bufferSize) { int pos = 0; while (pos < bytes.length) { int bl = bytes.length - pos; if (bl > this.bufferSize) { bl = this.bufferSize; } os.write(bytes, pos, bl); pos += bl; } } else { os.write(bytes); } }
public void writeTo(String obj, Class<?> type, Type genType, Annotation[] anns, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { String encoding = HttpUtils.getSetEncoding(mt, headers, StandardCharsets.UTF_8.name()); //REVISIT try to avoid instantiating the whole byte array byte[] bytes = obj.getBytes(encoding); if (bytes.length > bufferSize) { int pos = 0; while (pos < bytes.length) { int bl = bytes.length - pos; if (bl > bufferSize) { bl = bufferSize; } os.write(bytes, pos, bl); pos += bl; } } else { os.write(bytes); } } public void setBufferSize(int bufferSize) {
@Override public void writeTo(T t, Class<?> cls, Type genericType, Annotation[] anns, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { String prefix = getContext().getHttpServletRequest().getParameter("_jsonp"); boolean hasPrefix = !(null == prefix || prefix.isEmpty());//!isEmpty(prefix); if (hasPrefix) { os.write(prefix.getBytes(HttpUtils.getSetEncoding(m, headers, "UTF-8"))); os.write('('); } super.writeTo(t, cls, genericType, anns, m, headers, os); if (hasPrefix) { os.write(')'); } }
@Override public void writeTo(T t, Class<?> cls, Type genericType, Annotation[] anns, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { String prefix = getContext().getHttpServletRequest().getParameter("_jsonp"); boolean hasPrefix = !(null == prefix || prefix.isEmpty());//!isEmpty(prefix); if (hasPrefix) { os.write(prefix.getBytes(HttpUtils.getSetEncoding(m, headers, "UTF-8"))); os.write('('); } super.writeTo(t, cls, genericType, anns, m, headers, os); if (hasPrefix) { os.write(')'); } }
@SuppressWarnings("unchecked") public void writeTo(T obj, Class<?> c, Type t, Annotation[] anns, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException { MultivaluedMap<String, String> map = (MultivaluedMap<String, String>)(obj instanceof Form ? ((Form)obj).asMap() : obj); boolean encoded = keepEncoded(anns); String enc = HttpUtils.getSetEncoding(mt, headers, StandardCharsets.UTF_8.name()); FormUtils.writeMapToOutputStream(map, os, enc, encoded); }
@SuppressWarnings("unchecked") public void writeTo(T obj, Class<?> c, Type t, Annotation[] anns, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException, WebApplicationException { MultivaluedMap<String, String> map = (MultivaluedMap<String, String>)(obj instanceof Form ? ((Form)obj).getData() : obj); boolean encoded = keepEncoded(anns); String enc = HttpUtils.getSetEncoding(mt, headers, "UTF-8"); FormUtils.writeMapToOutputStream(map, os, enc, encoded); }
public void writeTo(T o, Class<?> clazz, Type genericType, Annotation[] annotations, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { XMLStreamWriter writer = null; try { String enc = HttpUtils.getSetEncoding(m, headers, StandardCharsets.UTF_8.name()); writer = createWriter(clazz, genericType, enc, os); writeToWriter(writer, o); } catch (Exception ex) { throw ExceptionUtils.toInternalServerErrorException(ex, null); } finally { StaxUtils.close(writer); } }
throws IOException { String encoding = HttpUtils.getSetEncoding(mt, headers, StandardCharsets.UTF_8.name());
public void writeTo(T source, Class<?> clazz, Type genericType, Annotation[] annotations, MediaType mt, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { String encoding = HttpUtils.getSetEncoding(mt, headers, "UTF-8"); XMLStreamReader reader = source instanceof Source ? StaxUtils.createXMLStreamReader((Source)source) : StaxUtils.createXMLStreamReader((Document)source); XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(os, encoding); try { StaxUtils.copy(reader, writer); } catch (XMLStreamException e) { throw ExceptionUtils.toInternalServerErrorException(e, null); } finally { try { reader.close(); } catch (XMLStreamException e) { //ignore } try { writer.flush(); writer.close(); } catch (XMLStreamException e) { //ignore } } }
public void writeTo(T obj, Class<?> cls, Type genericType, Annotation[] anns, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { try { String encoding = HttpUtils.getSetEncoding(m, headers, StandardCharsets.UTF_8.name()); if (InjectionUtils.isSupportedCollectionOrArray(cls)) { marshalCollection(cls, obj, genericType, encoding, os, m, anns); } else { Object actualObject = checkAdapter(obj, cls, anns, true); Class<?> actualClass = obj != actualObject || cls.isInterface() ? actualObject.getClass() : cls; marshal(actualObject, actualClass, genericType, encoding, os, m, anns); } } catch (JAXBException e) { handleJAXBException(e, false); } catch (WebApplicationException e) { throw e; } catch (Exception e) { LOG.warning(ExceptionUtils.getStackTrace(e)); throw ExceptionUtils.toInternalServerErrorException(e, null); } }
public void writeTo(T obj, Class<?> type, Type genericType, Annotation[] anns, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { if (type == null) { type = obj.getClass(); } if (genericType == null) { genericType = type; } AegisContext context = getAegisContext(type, genericType); AegisType aegisType = context.getTypeMapping().getType(genericType); AegisWriter<XMLStreamWriter> aegisWriter = context.createXMLStreamWriter(); try { String enc = HttpUtils.getSetEncoding(m, headers, StandardCharsets.UTF_8.name()); XMLStreamWriter xmlStreamWriter = createStreamWriter(aegisType.getSchemaType(), enc, os); // use type qname as element qname? xmlStreamWriter.writeStartDocument(); aegisWriter.write(obj, aegisType.getSchemaType(), false, xmlStreamWriter, aegisType); xmlStreamWriter.writeEndDocument(); xmlStreamWriter.close(); } catch (Exception e) { throw ExceptionUtils.toInternalServerErrorException(e, null); } }
public void writeTo(T o, Class<?> clazz, Type genericType, Annotation[] annotations, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { XMLStreamWriter writer = null; try { String enc = HttpUtils.getSetEncoding(m, headers, "UTF-8"); writer = createWriter(clazz, genericType, enc, os); writeToWriter(writer, o); } catch (Exception ex) { throw ExceptionUtils.toInternalServerErrorException(ex, null); } finally { StaxUtils.close(writer); } }
public void writeTo(T obj, Class<?> cls, Type genericType, Annotation[] anns, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { try { String encoding = HttpUtils.getSetEncoding(m, headers, null); if (InjectionUtils.isSupportedCollectionOrArray(cls)) { marshalCollection(cls, obj, genericType, encoding, os, m, anns); } else { Object actualObject = checkAdapter(obj, cls, anns, true); Class<?> actualClass = obj != actualObject || cls.isInterface() ? actualObject.getClass() : cls; marshal(actualObject, actualClass, genericType, encoding, os, m, anns); } } catch (JAXBException e) { handleJAXBException(e, false); } catch (WebApplicationException e) { throw e; } catch (Exception e) { LOG.warning(ExceptionUtils.getStackTrace(e)); throw ExceptionUtils.toInternalServerErrorException(e, null); } }
public void writeTo(T obj, Class<?> type, Type genericType, Annotation[] anns, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { if (type == null) { type = obj.getClass(); } if (genericType == null) { genericType = type; } AegisContext context = getAegisContext(type, genericType); AegisType aegisType = context.getTypeMapping().getType(genericType); AegisWriter<XMLStreamWriter> aegisWriter = context.createXMLStreamWriter(); try { String enc = HttpUtils.getSetEncoding(m, headers, StandardCharsets.UTF_8.name()); XMLStreamWriter xmlStreamWriter = createStreamWriter(aegisType.getSchemaType(), enc, os); // use type qname as element qname? xmlStreamWriter.writeStartDocument(); aegisWriter.write(obj, aegisType.getSchemaType(), false, xmlStreamWriter, aegisType); xmlStreamWriter.writeEndDocument(); xmlStreamWriter.close(); } catch (Exception e) { throw ExceptionUtils.toInternalServerErrorException(e, null); } }
public void writeTo(T obj, Class<?> type, Type genericType, Annotation[] anns, MediaType m, MultivaluedMap<String, Object> headers, OutputStream os) throws IOException { if (type == null) { type = obj.getClass(); } if (genericType == null) { genericType = type; } AegisContext context = getAegisContext(type, genericType); AegisType aegisType = context.getTypeMapping().getType(genericType); AegisWriter<XMLStreamWriter> aegisWriter = context.createXMLStreamWriter(); try { String enc = HttpUtils.getSetEncoding(m, headers, "UTF-8"); XMLStreamWriter xmlStreamWriter = createStreamWriter(aegisType.getSchemaType(), enc, os); // use type qname as element qname? xmlStreamWriter.writeStartDocument(); aegisWriter.write(obj, aegisType.getSchemaType(), false, xmlStreamWriter, aegisType); xmlStreamWriter.writeEndDocument(); xmlStreamWriter.close(); } catch (Exception e) { throw ExceptionUtils.toInternalServerErrorException(e, null); } }
String enc = HttpUtils.getSetEncoding(m, headers, "UTF-8");
try { String enc = HttpUtils.getSetEncoding(m, headers, StandardCharsets.UTF_8.name()); if (Document.class.isAssignableFrom(cls)) { writer = createWriter(obj, cls, genericType, enc, os, false);