42 |
import gnu.java.io.EncodingManager; |
import gnu.java.io.EncodingManager; |
43 |
import gnu.java.lang.CharData; |
import gnu.java.lang.CharData; |
44 |
|
|
|
import java.io.CharConversionException; |
|
45 |
import java.io.Serializable; |
import java.io.Serializable; |
46 |
import java.io.UnsupportedEncodingException; |
import java.io.UnsupportedEncodingException; |
47 |
import java.util.Comparator; |
import java.util.Comparator; |
318 |
{ |
{ |
319 |
if (offset < 0 || count < 0 || offset + count > data.length) |
if (offset < 0 || count < 0 || offset + count > data.length) |
320 |
throw new StringIndexOutOfBoundsException(); |
throw new StringIndexOutOfBoundsException(); |
321 |
try |
// XXX Consider using java.nio here. |
322 |
{ |
value = EncodingManager.getDecoder(encoding) |
323 |
// XXX Consider using java.nio here. |
.convertToChars(data, offset, count); |
|
value = EncodingManager.getDecoder(encoding) |
|
|
.convertToChars(data, offset, count); |
|
|
} |
|
|
catch (CharConversionException cce) |
|
|
{ |
|
|
throw new Error(cce); |
|
|
} |
|
324 |
this.offset = 0; |
this.offset = 0; |
325 |
this.count = value.length; |
this.count = value.length; |
326 |
} |
} |
370 |
{ |
{ |
371 |
if (offset < 0 || count < 0 || offset + count > data.length) |
if (offset < 0 || count < 0 || offset + count > data.length) |
372 |
throw new StringIndexOutOfBoundsException(); |
throw new StringIndexOutOfBoundsException(); |
373 |
try |
// XXX Consider using java.nio here. |
374 |
{ |
value = EncodingManager.getDecoder() |
375 |
// XXX Consider using java.nio here. |
.convertToChars(data, offset, count); |
|
value = EncodingManager.getDecoder() |
|
|
.convertToChars(data, offset, count); |
|
|
} |
|
|
catch (CharConversionException cce) |
|
|
{ |
|
|
throw new Error(cce); |
|
|
} |
|
376 |
this.offset = 0; |
this.offset = 0; |
377 |
this.count = value.length; |
this.count = value.length; |
378 |
} |
} |
533 |
* specified encoding method, so the result may be longer or shorter than |
* specified encoding method, so the result may be longer or shorter than |
534 |
* the String. For more encoding control, use |
* the String. For more encoding control, use |
535 |
* {@link java.nio.charset.CharsetEncoder}, and for valid character sets, |
* {@link java.nio.charset.CharsetEncoder}, and for valid character sets, |
536 |
* see {@link java.nio.charset.Charset}. The behavior is not specified if |
* see {@link java.nio.charset.Charset}. Unsupported characters get |
537 |
* the encoder encounters a problem; this implementation returns null. |
* replaced by an encoding specific byte. |
538 |
* |
* |
539 |
* @param enc encoding name |
* @param enc encoding name |
540 |
* @return the resulting byte array, or null on a problem |
* @return the resulting byte array |
541 |
* @throws NullPointerException if enc is null |
* @throws NullPointerException if enc is null |
542 |
* @throws UnsupportedEncodingException if encoding is not supported |
* @throws UnsupportedEncodingException if encoding is not supported |
543 |
* @since 1.1 |
* @since 1.1 |
544 |
*/ |
*/ |
545 |
public byte[] getBytes(String enc) throws UnsupportedEncodingException |
public byte[] getBytes(String enc) throws UnsupportedEncodingException |
546 |
{ |
{ |
547 |
try |
// XXX Consider using java.nio here. |
548 |
{ |
return EncodingManager.getEncoder(enc) |
549 |
// XXX Consider using java.nio here. |
.convertToBytes(value, offset, count); |
|
return EncodingManager.getEncoder(enc) |
|
|
.convertToBytes(value, offset, count); |
|
|
} |
|
|
catch (CharConversionException e) |
|
|
{ |
|
|
return null; |
|
|
} |
|
550 |
} |
} |
551 |
|
|
552 |
/** |
/** |
553 |
* Converts the Unicode characters in this String to a byte array. Uses the |
* Converts the Unicode characters in this String to a byte array. Uses the |
554 |
* encoding of the platform's default charset, so the result may be longer |
* encoding of the platform's default charset, so the result may be longer |
555 |
* or shorter than the String. For more encoding control, use |
* or shorter than the String. For more encoding control, use |
556 |
* {@link java.nio.charset.CharsetEncoder}. The behavior is not specified if |
* {@link java.nio.charset.CharsetEncoder}. Unsupported characters get |
557 |
* the encoder encounters a problem; this implementation returns null. |
* replaced by an encoding specific byte. |
558 |
* |
* |
559 |
* @return the resulting byte array, or null on a problem |
* @return the resulting byte array, or null on a problem |
560 |
* @since 1.1 |
* @since 1.1 |
561 |
*/ |
*/ |
562 |
public byte[] getBytes() |
public byte[] getBytes() |
563 |
{ |
{ |
564 |
try |
// XXX Consider using java.nio here. |
565 |
{ |
return EncodingManager.getEncoder() |
566 |
// XXX Consider using java.nio here. |
.convertToBytes(value, offset, count); |
|
return EncodingManager.getEncoder() |
|
|
.convertToBytes(value, offset, count); |
|
|
} |
|
|
catch (CharConversionException e) |
|
|
{ |
|
|
return null; |
|
|
} |
|
567 |
} |
} |
568 |
|
|
569 |
/** |
/** |