/** * Change the encoding used by this connection. * * @param encoding the new encoding to use * @throws IOException if something goes wrong */ public void setEncoding(Encoding encoding) throws IOException { if (this.encoding != null && this.encoding.name().equals(encoding.name())) { return; } // Close down any old writer. if (encodingWriter != null) { encodingWriter.close(); } this.encoding = encoding; // Intercept flush() downcalls from the writer; our caller // will call PGStream.flush() as needed. OutputStream interceptor = new FilterOutputStream(pg_output) { public void flush() throws IOException { } public void close() throws IOException { super.flush(); } }; encodingWriter = encoding.getEncodingWriter(interceptor); }
public synchronized Reader getCharacterStream() throws SQLException { Charset connectionCharset = Charset.forName(conn.getEncoding().name()); return new InputStreamReader(getBinaryStream(), connectionCharset); }
private Charset determineDatabaseCharset() { try { return Charset.forName(((PgConnection) connection()).getEncoding().name()); } catch (SQLException e) { throw new RuntimeException("Couldn't obtain encoding for database " + database(), e); } }
} catch (IOException ioe) { throw new PSQLException(GT.tr("Failed to convert binary xml data to encoding: {0}.", _conn.getEncoding().name()), PSQLState.DATA_ERROR, ioe); } finally { _byteArrayOutputStream = null;
long oid = lom.createLO(); LargeObject lob = lom.open(oid); Charset connectionCharset = Charset.forName(connection.getEncoding().name()); OutputStream los = lob.getOutputStream(); Writer lw = new OutputStreamWriter(los, connectionCharset);
_data = _conn.getEncoding().decode(_byteArrayOutputStream.toByteArray()); } catch (IOException ioe) { throw new PSQLException(GT.tr("Failed to convert binary xml data to encoding: {0}.", _conn.getEncoding().name()), PSQLState.DATA_ERROR, ioe); } finally { _byteArrayOutputStream = null;
return new DecodeResult(decoded, encoder.name()); } catch (IOException e) {
/** * Receives a fixed-size string from the backend, and tries to avoid "UTF-8 decode failed" * errors. * * @param len the length of the string to receive, in bytes. * @return the decoded string * @throws IOException if something wrong happens */ public EncodingPredictor.DecodeResult receiveErrorString(int len) throws IOException { if (!pg_input.ensureBytes(len)) { throw new EOFException(); } EncodingPredictor.DecodeResult res; try { String value = encoding.decode(pg_input.getBuffer(), pg_input.getIndex(), len); // no autodetect warning as the message was converted on its own res = new EncodingPredictor.DecodeResult(value, null); } catch (IOException e) { res = EncodingPredictor.decode(pg_input.getBuffer(), pg_input.getIndex(), len); if (res == null) { Encoding enc = Encoding.defaultEncoding(); String value = enc.decode(pg_input.getBuffer(), pg_input.getIndex(), len); res = new EncodingPredictor.DecodeResult(value, enc.name()); } } pg_input.skip(len); return res; }
private Charset determineDatabaseCharset() { try { return Charset.forName(((PgConnection) connection()).getEncoding().name()); } catch (SQLException e) { throw new RuntimeException("Couldn't obtain encoding for database " + database(), e); } }
_data = _conn.getEncoding().decode(_byteArrayOutputStream.toByteArray()); } catch (IOException ioe) { throw new PSQLException(GT.tr("Failed to convert binary xml data to encoding: {0}.", _conn.getEncoding().name()), PSQLState.DATA_ERROR, ioe); } finally { _byteArrayOutputStream = null;
_data = _conn.getEncoding().decode(_byteArrayOutputStream.toByteArray()); } catch (IOException ioe) { throw new PSQLException(GT.tr("Failed to convert binary xml data to encoding: {0}.", _conn.getEncoding().name()), PSQLState.DATA_ERROR, ioe); } finally { _byteArrayOutputStream = null;