Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Firebird Open Source J2ee connector - jdbc driver
   *
   * Distributable under LGPL license.
   * You may obtain a copy of the License at http://www.gnu.org/copyleft/lgpl.html
   *
   * This program is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * LGPL License for more details.
  *
  * This file was created by members of the firebird development team.
  * All individual contributions remain the Copyright (C) of those
  * individuals.  Contributors to this file are either listed here or
  * can be obtained from a CVS history command.
  *
  * All rights reserved.
  */
 
 package org.firebirdsql.jdbc.field;
 
 
Reader that is capable translating characters using the specified mapping. Should be used together with the isc_dpb_mapping_path parameter. If no mapping path is specified, it behaves as normal java.io.InputStreamReader.
 
 class TranslatingReader extends InputStreamReader {

    
Create instance of this class.

Parameters:
in input stream from which characters are read.
charsetName Java character set.
mappingPath path to the character mapping.
Returns:
instance of TranslatingReader
Throws:
java.sql.SQLException if the specified mapping path is not found.
 
     static TranslatingReader getInstance(InputStream inString charsetName,
             String mappingPaththrows SQLException {
         
         try {
             if (charsetName != null)
                 return new TranslatingReader(incharsetNamemappingPath);
             else
                 return new TranslatingReader(inmappingPath);
             
         } catch(UnsupportedEncodingException ex) {
             throw new FBSQLException("Cannot set character stream because " +
                 "the unsupported encoding is detected in the JVM: " +
                 charsetName + ". Please report this to the driver developers."
             );
         }
     }
     
     private char[] charMap;

    
Create instance of this class.

Parameters:
in input stream from which characters are read.
charsetName Java character set.
mappingPath path to the character mapping.
Throws:
java.io.UnsupportedEncodingException if the specified charset is not known.
java.sql.SQLException if the specified mapping path is not found.
 
     private TranslatingReader(InputStream inString charsetNameString mappingPath)
             throws UnsupportedEncodingExceptionSQLException {
         super(incharsetName);
         
         if (mappingPath != null)
              = EncodingFactory.getTranslator(mappingPath).getMapping();
         else
              = null;
     }
    
    
Create instance of this class.

Parameters:
in input stream from which characters are read.
mappingPath path to the character mapping.
Throws:
java.io.UnsupportedEncodingException if the specified charset is not known.
java.sql.SQLException if the specified mapping path is not found.
    private TranslatingReader(InputStream inString mappingPath)
            throws UnsupportedEncodingExceptionSQLException {
        super(in);
        
        if (mappingPath != null)
             = EncodingFactory.getTranslator(mappingPath).getMapping();
        else
             = null;
    }
    public int read() throws IOException {
        if ( == null)
            return super.read();
        else
            return [super.read()];
    }
    public int read(char[] cbufint offsetint lengththrows IOException {
        int result = super.read(cbufoffsetlength);
        
        if ( != null) {
            for (int i = 0; i < cbuf.lengthi++) {
                cbuf[i] = [cbuf[i]];
            }
        }
        
        return result;
    }
New to GrepCode? Check out our FAQ X