/** * Decode an array of bytes into a string. * * @param encodedString a bytearray containing the encoded string the string to encod * @return the decoded string * @throws IOException if something goes wrong */ public String decode(byte[] encodedString) throws IOException { return decode(encodedString, 0, encodedString.length); }
/** * Decode an array of bytes into a string. * * @param encodedString a byte array containing the string to decode * @return the decoded string * @throws IOException if something goes wrong */ public String decode(byte[] encodedString) throws IOException { return decode(encodedString, 0, encodedString.length); }
private boolean isMaster(QueryExecutor queryExecutor) throws SQLException, IOException { byte[][] results = SetupQueryRunner.run(queryExecutor, "show transaction_read_only", true); String value = queryExecutor.getEncoding().decode(results[0]); return value.equalsIgnoreCase("off"); } }
public static Map<String, String> fromBytes(byte[] b, Encoding encoding) throws SQLException { Map<String, String> m = new HashMap<String, String>(); int pos = 0; int numElements = ByteConverter.int4(b, pos); pos += 4; try { for (int i = 0; i < numElements; ++i) { int keyLen = ByteConverter.int4(b, pos); pos += 4; String key = encoding.decode(b, pos, keyLen); pos += keyLen; int valLen = ByteConverter.int4(b, pos); pos += 4; String val; if (valLen == -1) { val = null; } else { val = encoding.decode(b, pos, valLen); pos += valLen; } m.put(key, val); } } catch (IOException ioe) { throw new PSQLException( GT.tr( "Invalid character data was found. This is most likely caused by stored data containing characters that are invalid for the character set the database was created in. The most common example of this is storing 8bit data in a SQL_ASCII database."), PSQLState.DATA_ERROR, ioe); } return m; }
/** * Receives a fixed-size string from the backend. * * @param len the length of the string to receive, in bytes. * @return the decoded string * @throws IOException if something wrong happens */ public String receiveString(int len) throws IOException { if (!pg_input.ensureBytes(len)) { throw new EOFException(); } String res = encoding.decode(pg_input.getBuffer(), pg_input.getIndex(), len); pg_input.skip(len); return res; }
/** * Receives a fixed-size string from the backend. * * @param len the length of the string to receive, in bytes. * @return the decoded string */ public String ReceiveString(int len) throws IOException { if (!pg_input.ensureBytes(len)) { throw new EOFException(); } String res = encoding.decode(pg_input.getBuffer(), pg_input.getIndex(), len); pg_input.skip(len); return res; }
/** * Receives a null-terminated string from the backend. If we don't see a null, then we assume * something has gone wrong. * * @return string from back end * @throws IOException if an I/O error occurs, or end of file */ public String receiveString() throws IOException { int len = pg_input.scanCStringLength(); String res = encoding.decode(pg_input.getBuffer(), pg_input.getIndex(), len - 1); pg_input.skip(len); return res; }
_data = _conn.getEncoding().decode(_byteArrayOutputStream.toByteArray()); } catch (IOException ioe) { throw new PSQLException(GT.tr("Failed to convert binary xml data to encoding: {0}.",
_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);
/** * Receives a null-terminated string from the backend. If we don't see a * null, then we assume something has gone wrong. * * @return string from back end * @exception IOException if an I/O error occurs, or end of file */ public String ReceiveString() throws IOException { int len = pg_input.scanCStringLength(); String res = encoding.decode(pg_input.getBuffer(), pg_input.getIndex(), len - 1); pg_input.skip(len); return res; }
/** * Pass results of a COPY TO STDOUT query from database into a Writer. * @param sql COPY TO STDOUT statement * @param to the stream to write the results to (row by row) * @return number of rows updated for server 8.2 or newer; -1 for older * @throws SQLException on database usage errors * @throws IOException upon writer or database connection failure */ public long copyOut(final String sql, Writer to) throws SQLException, IOException { byte[] buf; CopyOut cp = copyOut(sql); try { while ( (buf = cp.readFromCopy()) != null ) { to.write(encoding.decode(buf)); } return cp.getHandledRowCount(); } finally { // see to it that we do not leave the connection locked if(cp.isActive()) cp.cancelCopy(); } }
public String getString(int columnIndex) throws SQLException { checkResultSet( columnIndex ); if (wasNullFlag) return null; Encoding encoding = connection.getEncoding(); try { return trimString(columnIndex, encoding.decode(this_row[columnIndex - 1])); } catch (IOException ioe) { throw new PSQLException(GT.tr("Invalid character data was found. This is most likely caused by stored data containing characters that are invalid for the character set the database was created in. The most common example of this is storing 8bit data in a SQL_ASCII database."), PSQLState.DATA_ERROR, ioe); } }
private void runInitialQueries(ProtocolConnectionImpl protoConnection, Properties info, Logger logger) throws SQLException, IOException { byte[][] results = SetupQueryRunner.run(protoConnection, "set datestyle = 'ISO'; select version(), case when pg_encoding_to_char(1) = 'SQL_ASCII' then 'UNKNOWN' else getdatabaseencoding() end", true); String rawDbVersion = protoConnection.getEncoding().decode(results[0]); StringTokenizer versionParts = new StringTokenizer(rawDbVersion); String dbEncoding = (results[1] == null ? null : protoConnection.getEncoding().decode(results[1])); if (logger.logDebug()) String value = protoConnection.getEncoding().decode(results[0]); protoConnection.setStandardConformingStrings(value.equalsIgnoreCase("on"));
/** * 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; }
String decoded = encoder.decode(bytes, offset, length); if (decoded.indexOf(65533) != -1) {
try { while ((buf = cp.readFromCopy()) != null) { to.write(encoding.decode(buf));
return trimString(columnIndex, encoding.decode(this_row[columnIndex - 1])); } catch (IOException ioe) { throw new PSQLException(
case Oid.VARCHAR: Encoding encoding = connection.getEncoding(); arr[i] = encoding.decode(fieldBytes, pos, len); break; case Oid.BOOL:
/** * Decode an array of bytes into a string. * * @param encodedString a bytearray containing the encoded string the string to encod * @return the decoded string * @throws IOException if something goes wrong */ public String decode(byte[] encodedString) throws IOException { return decode(encodedString, 0, encodedString.length); }
/** * Decode an array of bytes into a string. * * @param encodedString a bytearray containing the encoded string the string to encod * @return the decoded string * @throws IOException if something goes wrong */ public String decode(byte[] encodedString) throws IOException { return decode(encodedString, 0, encodedString.length); }