Example #1
0
  @Override
  public int read() throws IOException {
    int ch = super.read();

    if (ch < 0) {
      return ch;
    }

    return converter.convert((char) ch);
  }
Example #2
0
  @Override
  public int read(char[] cbuf, int off, int len) throws IOException {
    int count = super.read(cbuf, off, len);

    if (count > 0) {
      converter.convert(cbuf, off, count);
    }

    return count;
  }
 // Perform an OS/400 CCSID to Unicode conversion.
 final String byteArrayToString(
     byte[] buf, int offset, int length, BidiConversionProperties properties) {
   if (Trace.traceOn_)
     Trace.log(
         Trace.CONVERSION,
         "Converting byte array to string for ccsid: " + ccsid_,
         buf,
         offset,
         length);
   // Length could be twice as long because of surrogates
   char[] dest = new char[length];
   int to = 0;
   for (int i = 0; i < length / 2; ++i) {
     try {
       int fromIndex =
           ((0x00FF & buf[(i * 2) + offset]) << 8) + (0x00FF & buf[(i * 2) + 1 + offset]);
       dest[to] = toUnicode_[fromIndex];
       // Check if surrogate lookup needed.
       if (dest[to] == 0xD800) {
         if (toUnicodeSurrogate_ != null) {
           char[] surrogates = toUnicodeSurrogate_[fromIndex];
           if (surrogates != null) {
             dest[to] = surrogates[0];
             to++;
             dest[to] = surrogates[1];
             to++;
           } else {
             // surrogate not defined, replace with sub
             dest[to] = dbSubUnic_;
             to++;
           }
         } else {
           // Not handling surrogates, replace with sub
           dest[to] = dbSubUnic_;
           to++;
         }
       } else {
         // Single character.  Increment counter;
         to++;
       }
     } catch (ArrayIndexOutOfBoundsException aioobe) {
       // Swallow this if we are doing fault-tolerant conversion.
       if (!CharConverter.isFaultTolerantConversion()) {
         throw aioobe;
       }
     }
   }
   if (Trace.traceOn_)
     Trace.log(
         Trace.CONVERSION,
         "Destination string for ccsid: " + ccsid_,
         ConvTable.dumpCharArray(dest));
   return String.copyValueOf(dest, 0, to);
 }
Example #4
0
 public CharConvertReader(Reader in, String converterName) {
   this(in, CharConverter.getInstance(converterName));
 }