/** * Construct an Encoding for a given JVM encoding. * * @param jvmEncoding the name of the JVM encoding * @return an Encoding instance for the specified encoding, * or an Encoding instance for the default JVM encoding if the * specified encoding is unavailable. */ public static Encoding getJVMEncoding(String jvmEncoding) { if (isAvailable(jvmEncoding)) { if (jvmEncoding.equals("UTF-8") || jvmEncoding.equals("UTF8")) return new UTF8Encoding(jvmEncoding); else return new Encoding(jvmEncoding); } else return defaultEncoding(); }
public static DecodeResult decode(byte[] bytes, int offset, int length) { Encoding defaultEncoding = Encoding.defaultEncoding(); for (Translation tr : FATAL_TRANSLATIONS) { for (String encoding : tr.encodings) {
protoConnection.setEncoding(Encoding.defaultEncoding());
/** * 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; }
/** * Construct an Encoding for a given JVM encoding. * * @param jvmEncoding the name of the JVM encoding * @return an Encoding instance for the specified encoding, * or an Encoding instance for the default JVM encoding if the * specified encoding is unavailable. */ public static Encoding getJVMEncoding(String jvmEncoding) { if (isAvailable(jvmEncoding)) { if (jvmEncoding.equals("UTF-8") || jvmEncoding.equals("UTF8")) return new UTF8Encoding(jvmEncoding); else return new Encoding(jvmEncoding); } else return defaultEncoding(); }
/** * Construct an Encoding for a given JVM encoding. * * @param jvmEncoding the name of the JVM encoding * @return an Encoding instance for the specified encoding, * or an Encoding instance for the default JVM encoding if the * specified encoding is unavailable. */ public static Encoding getJVMEncoding(String jvmEncoding) { if (isAvailable(jvmEncoding)) { if (jvmEncoding.equals("UTF-8") || jvmEncoding.equals("UTF8")) return new UTF8Encoding(jvmEncoding); else return new Encoding(jvmEncoding); } else return defaultEncoding(); }
protoConnection.setEncoding(Encoding.defaultEncoding());
protoConnection.setEncoding(Encoding.defaultEncoding());