/** * Returns a new byte array containing the characters of this string encoded using the * given charset. * * <p>The behavior when this string cannot be represented in the given charset * is to replace malformed input and unmappable characters with the charset's default * replacement byte array. Use {@link java.nio.charset.CharsetEncoder} for more control. * * @since 1.6 */ public byte[] getBytes(Charset charset) { String canonicalCharsetName = charset.name(); if (canonicalCharsetName.equals("UTF-8")) { return Charsets.toUtf8Bytes(value, offset, count); } else if (canonicalCharsetName.equals("ISO-8859-1")) { return Charsets.toIsoLatin1Bytes(value, offset, count); } else if (canonicalCharsetName.equals("US-ASCII")) { return Charsets.toAsciiBytes(value, offset, count); } else if (canonicalCharsetName.equals("UTF-16BE")) { return Charsets.toBigEndianUtf16Bytes(value, offset, count); } else { CharBuffer chars = CharBuffer.wrap(this.value, this.offset, this.count); ByteBuffer buffer = charset.encode(chars.asReadOnlyBuffer()); byte[] bytes = new byte[buffer.limit()]; buffer.get(bytes); return bytes; } }
/** * Returns a new byte array containing the characters of this string encoded using the * given charset. * * <p>The behavior when this string cannot be represented in the given charset * is to replace malformed input and unmappable characters with the charset's default * replacement byte array. Use {@link java.nio.charset.CharsetEncoder} for more control. * * @since 1.6 */ public byte[] getBytes(Charset charset) { String canonicalCharsetName = charset.name(); if (canonicalCharsetName.equals("UTF-8")) { return Charsets.toUtf8Bytes(value, offset, count); } else if (canonicalCharsetName.equals("ISO-8859-1")) { return Charsets.toIsoLatin1Bytes(value, offset, count); } else if (canonicalCharsetName.equals("US-ASCII")) { return Charsets.toAsciiBytes(value, offset, count); } else if (canonicalCharsetName.equals("UTF-16BE")) { return Charsets.toBigEndianUtf16Bytes(value, offset, count); } else { CharBuffer chars = CharBuffer.wrap(this.value, this.offset, this.count); ByteBuffer buffer = charset.encode(chars.asReadOnlyBuffer()); byte[] bytes = new byte[buffer.limit()]; buffer.get(bytes); return bytes; } }
/** * Returns a new byte array containing the characters of this string encoded using the * given charset. * * <p>The behavior when this string cannot be represented in the given charset * is to replace malformed input and unmappable characters with the charset's default * replacement byte array. Use {@link java.nio.charset.CharsetEncoder} for more control. * * @since 1.6 */ public byte[] getBytes(Charset charset) { String canonicalCharsetName = charset.name(); if (canonicalCharsetName.equals("UTF-8")) { return Charsets.toUtf8Bytes(value, offset, count); } else if (canonicalCharsetName.equals("ISO-8859-1")) { return Charsets.toIsoLatin1Bytes(value, offset, count); } else if (canonicalCharsetName.equals("US-ASCII")) { return Charsets.toAsciiBytes(value, offset, count); } else if (canonicalCharsetName.equals("UTF-16BE")) { return Charsets.toBigEndianUtf16Bytes(value, offset, count); } else { CharBuffer chars = CharBuffer.wrap(this.value, this.offset, this.count); ByteBuffer buffer = charset.encode(chars.asReadOnlyBuffer()); byte[] bytes = new byte[buffer.limit()]; buffer.get(bytes); return bytes; } }
/** * Returns a new byte array containing the characters of this string encoded using the * given charset. * * <p>The behavior when this string cannot be represented in the given charset * is to replace malformed input and unmappable characters with the charset's default * replacement byte array. Use {@link java.nio.charset.CharsetEncoder} for more control. * * @since 1.6 */ public byte[] getBytes(Charset charset) { String canonicalCharsetName = charset.name(); if (canonicalCharsetName.equals("UTF-8")) { return Charsets.toUtf8Bytes(value, offset, count); } else if (canonicalCharsetName.equals("ISO-8859-1")) { return Charsets.toIsoLatin1Bytes(value, offset, count); } else if (canonicalCharsetName.equals("US-ASCII")) { return Charsets.toAsciiBytes(value, offset, count); } else if (canonicalCharsetName.equals("UTF-16BE")) { return Charsets.toBigEndianUtf16Bytes(value, offset, count); } else { CharBuffer chars = CharBuffer.wrap(this.value, this.offset, this.count); ByteBuffer buffer = charset.encode(chars.asReadOnlyBuffer()); byte[] bytes = new byte[buffer.limit()]; buffer.get(bytes); return bytes; } }
/** * Returns a new byte array containing the characters of this string encoded using the * given charset. * * <p>The behavior when this string cannot be represented in the given charset * is to replace malformed input and unmappable characters with the charset's default * replacement byte array. Use {@link java.nio.charset.CharsetEncoder} for more control. * * @since 1.6 */ public byte[] getBytes(Charset charset) { String canonicalCharsetName = charset.name(); if (canonicalCharsetName.equals("UTF-8")) { return Charsets.toUtf8Bytes(value, offset, count); } else if (canonicalCharsetName.equals("ISO-8859-1")) { return Charsets.toIsoLatin1Bytes(value, offset, count); } else if (canonicalCharsetName.equals("US-ASCII")) { return Charsets.toAsciiBytes(value, offset, count); } else if (canonicalCharsetName.equals("UTF-16BE")) { return Charsets.toBigEndianUtf16Bytes(value, offset, count); } else { CharBuffer chars = CharBuffer.wrap(this.value, this.offset, this.count); ByteBuffer buffer = charset.encode(chars.asReadOnlyBuffer()); byte[] bytes = new byte[buffer.limit()]; buffer.get(bytes); return bytes; } }
/** * Returns a new byte array containing the characters of this string encoded using the * given charset. * * <p>The behavior when this string cannot be represented in the given charset * is to replace malformed input and unmappable characters with the charset's default * replacement byte array. Use {@link java.nio.charset.CharsetEncoder} for more control. * * @since 1.6 */ public byte[] getBytes(Charset charset) { String canonicalCharsetName = charset.name(); if (canonicalCharsetName.equals("UTF-8")) { return Charsets.toUtf8Bytes(value, offset, count); } else if (canonicalCharsetName.equals("ISO-8859-1")) { return Charsets.toIsoLatin1Bytes(value, offset, count); } else if (canonicalCharsetName.equals("US-ASCII")) { return Charsets.toAsciiBytes(value, offset, count); } else if (canonicalCharsetName.equals("UTF-16BE")) { return Charsets.toBigEndianUtf16Bytes(value, offset, count); } else { CharBuffer chars = CharBuffer.wrap(this.value, this.offset, this.count); ByteBuffer buffer = charset.encode(chars.asReadOnlyBuffer()); byte[] bytes = new byte[buffer.limit()]; buffer.get(bytes); return bytes; } }
/** * Returns a new byte array containing the characters of this string encoded using the * given charset. * * <p>The behavior when this string cannot be represented in the given charset * is to replace malformed input and unmappable characters with the charset's default * replacement byte array. Use {@link java.nio.charset.CharsetEncoder} for more control. * * @since 1.6 */ public byte[] getBytes(Charset charset) { String canonicalCharsetName = charset.name(); if (canonicalCharsetName.equals("UTF-8")) { return Charsets.toUtf8Bytes(value, offset, count); } else if (canonicalCharsetName.equals("ISO-8859-1")) { return Charsets.toIsoLatin1Bytes(value, offset, count); } else if (canonicalCharsetName.equals("US-ASCII")) { return Charsets.toAsciiBytes(value, offset, count); } else if (canonicalCharsetName.equals("UTF-16BE")) { return Charsets.toBigEndianUtf16Bytes(value, offset, count); } else { CharBuffer chars = CharBuffer.wrap(this.value, this.offset, this.count); ByteBuffer buffer = charset.encode(chars.asReadOnlyBuffer()); byte[] bytes = new byte[buffer.limit()]; buffer.get(bytes); return bytes; } }