/** * Ensures that, when setting content bytes, the bytes' encoding is reflected * in the current Content-Type header. * Note, this method does NOT override existing Content-Type values if newEncoding is null. * This allows charset to be set by header only, along with a byte array -- a very typical, * and important, pattern when creating an HttpResponse in an HttpFetcher. */ @Override protected void setContentBytesState(byte[] newBytes, Charset newEncoding) { super.setContentBytesState(newBytes, newEncoding); // Set the new encoding of the raw bytes, in order to ensure that // Content-Type headers are in sync w/ the content's encoding. if (newEncoding != null) setEncoding(newEncoding); }
/** * Sets the object's contentBytes as the given raw input. If ever interpreted * as a String, the data will be decoded as the encoding specified. * Note, this operation may clear the document if the content has changed. * Also note, it's mandated that the new bytes array will NOT be modified * by the caller of this API. The array is not copied, for performance reasons. * If the caller may modify a byte array, it MUST pass in a new copy. * @param newBytes New content. */ public void setContentBytes(byte[] newBytes, Charset newEncoding) { if (contentBytes == null || !Arrays.equals(contentBytes, newBytes)) { setContentBytesState(newBytes, newEncoding); document = null; contentSource = null; content = null; incrementNumChanges(); } }
/** * Ensures that, when setting content bytes, the bytes' encoding is reflected * in the current Content-Type header. * Note, this method does NOT override existing Content-Type values if newEncoding is null. * This allows charset to be set by header only, along with a byte array -- a very typical, * and important, pattern when creating an HttpResponse in an HttpFetcher. */ @Override protected void setContentBytesState(byte[] newBytes, Charset newEncoding) { super.setContentBytesState(newBytes, newEncoding); // Set the new encoding of the raw bytes, in order to ensure that // Content-Type headers are in sync w/ the content's encoding. if (newEncoding != null) setEncoding(newEncoding); }
/** * Ensures that, when setting content bytes, the bytes' encoding is reflected * in the current Content-Type header. * Note, this method does NOT override existing Content-Type values if newEncoding is null. * This allows charset to be set by header only, along with a byte array -- a very typical, * and important, pattern when creating an HttpResponse in an HttpFetcher. */ @Override protected void setContentBytesState(byte[] newBytes, Charset newEncoding) { super.setContentBytesState(newBytes, newEncoding); // Set the new encoding of the raw bytes, in order to ensure that // Content-Type headers are in sync w/ the content's encoding. if (newEncoding != null) setEncoding(newEncoding); }
/** * Sets the object's contentBytes as the given raw input. If ever interpreted * as a String, the data will be decoded as the encoding specified. * Note, this operation may clear the document if the content has changed. * Also note, it's mandated that the new bytes array will NOT be modified * by the caller of this API. The array is not copied, for performance reasons. * If the caller may modify a byte array, it MUST pass in a new copy. * @param newBytes New content. */ public void setContentBytes(byte[] newBytes, Charset newEncoding) { if (contentBytes == null || !Arrays.equals(contentBytes, newBytes)) { setContentBytesState(newBytes, newEncoding); document = null; contentSource = null; content = null; incrementNumChanges(); } }
/** * Sets the object's contentBytes as the given raw input. If ever interpreted * as a String, the data will be decoded as the encoding specified. * Note, this operation may clear the document if the content has changed. * Also note, it's mandated that the new bytes array will NOT be modified * by the caller of this API. The array is not copied, for performance reasons. * If the caller may modify a byte array, it MUST pass in a new copy. * @param newBytes New content. */ public void setContentBytes(byte[] newBytes, Charset newEncoding) { if (contentBytes == null || !Arrays.equals(contentBytes, newBytes)) { setContentBytesState(newBytes, newEncoding); document = null; contentSource = null; content = null; incrementNumChanges(); } }
protected byte[] getRawContentBytes() { if (contentBytes == null) { if (contentSource != null) { try { setContentBytesState(IOUtils.toByteArray(contentSource.getResponse()), contentSource.getEncodingCharset()); contentSource = null; } catch (IOException e) { // Doesn't occur; responseBytes wrapped as a ByteArrayInputStream. } } else if (content != null) { // If retrieving a String here, we've already converted to UTF8. // Be sure to reflect this when setting bytes. // In the case of HttpResponseBuilder, this re-sets charset in Content-Type // to UTF-8 rather than whatever it was before. We do this to standardize // on UTF-8 for all String handling. setContentBytesState(CharsetUtil.getUtf8Bytes(content), Charsets.UTF_8); } else if (document != null) { setContentBytesState( CharsetUtil.getUtf8Bytes(HtmlSerialization.serialize(document)), Charsets.UTF_8); } } return contentBytes; }
protected byte[] getRawContentBytes() { if (contentBytes == null) { if (contentSource != null) { try { setContentBytesState(IOUtils.toByteArray(contentSource.getResponse()), contentSource.getEncodingCharset()); contentSource = null; } catch (IOException e) { // Doesn't occur; responseBytes wrapped as a ByteArrayInputStream. } } else if (content != null) { // If retrieving a String here, we've already converted to UTF8. // Be sure to reflect this when setting bytes. // In the case of HttpResponseBuilder, this re-sets charset in Content-Type // to UTF-8 rather than whatever it was before. We do this to standardize // on UTF-8 for all String handling. setContentBytesState(CharsetUtil.getUtf8Bytes(content), Charsets.UTF_8); } else if (document != null) { setContentBytesState( CharsetUtil.getUtf8Bytes(HtmlSerialization.serialize(document)), Charsets.UTF_8); } } return contentBytes; }
protected byte[] getRawContentBytes() { if (contentBytes == null) { if (contentSource != null) { try { setContentBytesState(IOUtils.toByteArray(contentSource.getResponse()), contentSource.getEncodingCharset()); contentSource = null; } catch (IOException e) { // Doesn't occur; responseBytes wrapped as a ByteArrayInputStream. } } else if (content != null) { // If retrieving a String here, we've already converted to UTF8. // Be sure to reflect this when setting bytes. // In the case of HttpResponseBuilder, this re-sets charset in Content-Type // to UTF-8 rather than whatever it was before. We do this to standardize // on UTF-8 for all String handling. setContentBytesState(CharsetUtil.getUtf8Bytes(content), Charsets.UTF_8); } else if (document != null) { setContentBytesState( CharsetUtil.getUtf8Bytes(HtmlSerialization.serialize(document)), Charsets.UTF_8); } } return contentBytes; }