/** * Converts the byte array of HTTP content characters to a string. If * the specified charset is not supported, default system encoding * is used. * * @param data the byte array to be encoded * @param charset the desired character encoding * @return The result of the conversion. * * @since 3.0 */ public static String getString(final byte[] data, String charset) { return getString(data, 0, data.length, charset); }
return EncodingUtil.getString(rawdata, getResponseCharSet()); } else { return null;
EncodingUtil.getString(rawdata, 0, len - offset, charset); if (Wire.HEADER_WIRE.enabled()) { String logoutput = result;
/** * Returns the response body of the HTTP method, if any, as a {@link String}. * If response body is not available or cannot be read, returns <tt>null</tt> * The string conversion on the data is done using the character encoding specified * in <tt>Content-Type</tt> header. Buffers the response and this method can be * called several times yielding the same result each time. * * Note: This will cause the entire response body to be buffered in memory. A * malicious server may easily exhaust all the VM memory. It is strongly * recommended, to use getResponseAsStream if the content length of the response * is unknown or resonably large. * * @return The response body or <code>null</code>. * * @throws IOException If an I/O (transport) problem occurs while obtaining the * response body. */ public String getResponseBodyAsString() throws IOException { byte[] rawdata = null; if (responseAvailable()) { rawdata = getResponseBody(); } if (rawdata != null) { return EncodingUtil.getString(rawdata, getResponseCharSet()); } else { return null; } }
throw new URIException(e.getMessage()); return EncodingUtil.getString(rawdata, charset);
/** * Unescape and decode a given string regarded as an escaped string with the * default protocol charset. * * @param escaped a string * @return the unescaped string * * @throws URIException if the string cannot be decoded (invalid) * * @see URI#getDefaultProtocolCharset */ public static String decode(String escaped) throws URIException { try { byte[] rawdata = URLCodec.decodeUrl(EncodingUtil.getAsciiBytes(escaped)); return EncodingUtil.getString(rawdata, URI.getDefaultProtocolCharset()); } catch (DecoderException e) { throw new URIException(e.getMessage()); } }
/** * Converts the byte array of HTTP content characters to a string. If * the specified charset is not supported, default system encoding * is used. * * @param data the byte array to be encoded * @param charset the desired character encoding * @return The result of the conversion. * * @since 3.0 */ public static String getString(final byte[] data, String charset) { return getString(data, 0, data.length, charset); }
/** * Converts the byte array of HTTP content characters to a string. If * the specified charset is not supported, default system encoding * is used. * * @param data the byte array to be encoded * @param charset the desired character encoding * @return The result of the conversion. * * @since 3.0 */ public static String getString(final byte[] data, String charset) { return getString(data, 0, data.length, charset); }
/** * Converts the byte array of HTTP content characters to a string. If * the specified charset is not supported, default system encoding * is used. * * @param data the byte array to be encoded * @param charset the desired character encoding * @return The result of the conversion. * * @since 3.0 */ public static String getString(final byte[] data, String charset) { return getString(data, 0, data.length, charset); }
/** * Converts the byte array of HTTP content characters to a string. If * the specified charset is not supported, default system encoding * is used. * * @param data the byte array to be encoded * @param charset the desired character encoding * @return The result of the conversion. * * @since 3.0 */ public static String getString(final byte[] data, String charset) { return getString(data, 0, data.length, charset); }
protected static String decode(String component, String charset) throws URIException { if (component == null) { throw new IllegalArgumentException( "Component array of chars may not be null"); } byte[] rawdata = null; // try { rawdata = LaxURLCodec.decodeUrlLoose(EncodingUtil .getAsciiBytes(component)); // } catch (DecoderException e) { // throw new URIException(e.getMessage()); // } return EncodingUtil.getString(rawdata, charset); }
protected static String decode(String component, String charset) throws URIException { if (component == null) { throw new IllegalArgumentException( "Component array of chars may not be null"); } byte[] rawdata = null; // try { rawdata = LaxURLCodec.decodeUrlLoose(EncodingUtil .getAsciiBytes(component)); // } catch (DecoderException e) { // throw new URIException(e.getMessage()); // } return EncodingUtil.getString(rawdata, charset); }
protected static String decode(String component, String charset) throws URIException { if (component == null) { throw new IllegalArgumentException( "Component array of chars may not be null"); } byte[] rawdata = null; // try { rawdata = LaxURLCodec.decodeUrlLoose(EncodingUtil .getAsciiBytes(component)); // } catch (DecoderException e) { // throw new URIException(e.getMessage()); // } return EncodingUtil.getString(rawdata, charset); }
/** * Returns the response body of the HTTP method, if any, as a {@link String}. * If response body is not available or cannot be read, returns <tt>null</tt> * The string conversion on the data is done using the character encoding specified * in <tt>Content-Type</tt> header. Buffers the response and this method can be * called several times yielding the same result each time. * * Note: This will cause the entire response body to be buffered in memory. A * malicious server may easily exhaust all the VM memory. It is strongly * recommended, to use getResponseAsStream if the content length of the response * is unknown or resonably large. * * @return The response body or <code>null</code>. * * @throws IOException If an I/O (transport) problem occurs while obtaining the * response body. */ public String getResponseBodyAsString() throws IOException { byte[] rawdata = null; if (responseAvailable()) { rawdata = getResponseBody(); } if (rawdata != null) { return EncodingUtil.getString(rawdata, getResponseCharSet()); } else { return null; } }
/** * Unescape and decode a given string regarded as an escaped string with the * default protocol charset. * * @param escaped a string * @return the unescaped string * * @throws URIException if the string cannot be decoded (invalid) * * @see URI#getDefaultProtocolCharset */ public static String decode(String escaped) throws URIException { try { byte[] rawdata = URLCodec.decodeUrl(EncodingUtil.getAsciiBytes(escaped)); return EncodingUtil.getString(rawdata, URI.getDefaultProtocolCharset()); } catch (DecoderException e) { throw new URIException(e.getMessage()); } }
/** * Unescape and decode a given string regarded as an escaped string with the * default protocol charset. * * @param escaped a string * @return the unescaped string * * @throws URIException if the string cannot be decoded (invalid) * * @see URI#getDefaultProtocolCharset */ public static String decode(String escaped) throws URIException { try { byte[] rawdata = URLCodec.decodeUrl(EncodingUtil.getAsciiBytes(escaped)); return EncodingUtil.getString(rawdata, URI.getDefaultProtocolCharset()); } catch (DecoderException e) { throw new URIException(e.getMessage()); } }
/** * Unescape and decode a given string regarded as an escaped string with the * default protocol charset. * * @param escaped a string * @return the unescaped string * * @throws URIException if the string cannot be decoded (invalid) * * @see URI#getDefaultProtocolCharset */ public static String decode(String escaped) throws URIException { try { byte[] rawdata = URLCodec.decodeUrl(EncodingUtil.getAsciiBytes(escaped)); return EncodingUtil.getString(rawdata, URI.getDefaultProtocolCharset()); } catch (DecoderException e) { throw new URIException(e.getMessage()); } }
/** * Unescape and decode a given string regarded as an escaped string with the * default protocol charset. * * @param escaped a string * @return the unescaped string * * @throws URIException if the string cannot be decoded (invalid) * * @see URI#getDefaultProtocolCharset */ public static String decode(String escaped) throws URIException { try { byte[] rawdata = URLCodec.decodeUrl(EncodingUtil.getAsciiBytes(escaped)); return EncodingUtil.getString(rawdata, URI.getDefaultProtocolCharset()); } catch (DecoderException e) { throw new URIException(e.getMessage()); } }
private CaptureSearchResult adaptWARCHTTPResponse(CaptureSearchResult result, WARCRecord rec) throws IOException { ArchiveRecordHeader header = rec.getHeader(); // need to parse the documents HTTP message and headers here: WARCReader // does not implement this... yet.. byte [] statusBytes = LaxHttpParser.readRawLine(rec); int eolCharCount = getEolCharsCount(statusBytes); if (eolCharCount <= 0) { throw new RecoverableIOException("Failed to read http status where one " + " was expected: " + ((statusBytes == null) ? "(null)" : new String(statusBytes))); } String statusLine = EncodingUtil.getString(statusBytes, 0, statusBytes.length - eolCharCount, ARCConstants.DEFAULT_ENCODING); if ((statusLine == null) || !StatusLine.startsWithHTTP(statusLine)) { throw new RecoverableIOException("Failed parse of http status line."); } StatusLine status = new StatusLine(statusLine); result.setHttpCode(String.valueOf(status.getStatusCode())); Header[] headers = LaxHttpParser.parseHeaders(rec, ARCConstants.DEFAULT_ENCODING); annotater.annotateHTTPContent(result,rec,headers,header.getMimetype()); return result; }
private CaptureSearchResult adaptWARCHTTPResponse(CaptureSearchResult result, WARCRecord rec) throws IOException { ArchiveRecordHeader header = rec.getHeader(); // need to parse the documents HTTP message and headers here: WARCReader // does not implement this... yet.. byte [] statusBytes = LaxHttpParser.readRawLine(rec); int eolCharCount = getEolCharsCount(statusBytes); if (eolCharCount <= 0) { throw new RecoverableIOException("Failed to read http status where one " + " was expected: " + ((statusBytes == null) ? "(null)" : new String(statusBytes))); } String statusLine = EncodingUtil.getString(statusBytes, 0, statusBytes.length - eolCharCount, ARCConstants.DEFAULT_ENCODING); if ((statusLine == null) || !StatusLine.startsWithHTTP(statusLine)) { throw new RecoverableIOException("Failed parse of http status line."); } StatusLine status = new StatusLine(statusLine); result.setHttpCode(String.valueOf(status.getStatusCode())); Header[] headers = LaxHttpParser.parseHeaders(rec, ARCConstants.DEFAULT_ENCODING); annotater.annotateHTTPContent(result,rec,headers,header.getMimetype()); return result; }