List of usage examples for org.apache.commons.codec Charsets ISO_8859_1
Charset ISO_8859_1
To view the source code for org.apache.commons.codec Charsets ISO_8859_1.
Click Source Link
From source file:TestReadCustData.java
public static void main(String[] args) { AgentLoader.loadAgentFromClasspath("avaje-ebeanorm-agent", "debug=1"); List<Customer> lCust = new ArrayList<>(); try {//from w w w .ja va 2 s. c o m List<String> s = Files.readAllLines(Paths.get("customer.txt"), Charsets.ISO_8859_1); for (String s1 : s) { if (!s1.startsWith("GRUP")) { Customer c = new Customer(); try { c.setId(Long.parseLong(s1.split("~")[3])); } catch (ArrayIndexOutOfBoundsException arrex) { c.setId(Long.parseLong(s1.split("~")[3])); } try { c.setNama(s1.split("~")[4]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setNama(""); } try { c.setShipto(s1.split("~")[9]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setShipto(""); } try { c.setKota(s1.split("~")[12]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setKota(""); } try { c.setProvinsi(s1.split("~")[13]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setProvinsi(""); } try { c.setKodePos(s1.split("~")[14]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setKodePos(""); } try { c.setNamaArea(s1.split("~")[2]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setNamaArea(""); } try { c.setDKLK(s1.split("~")[15]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setDKLK(""); } try { c.setCreditLimit(Long.parseLong(s1.split("~")[16])); } catch (ArrayIndexOutOfBoundsException arrex) { c.setCreditLimit(new Long(0)); } try { c.setNpwp(s1.split("~")[11]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setNpwp(""); } try { c.setNamaWajibPajak(s1.split("~")[10]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setNamaWajibPajak(""); } try { c.setCreationDate(s1.split("~")[6]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setCreationDate(""); } try { c.setLastUpdateBy(s1.split("~")[17]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setLastUpdateBy(""); } try { c.setLastUpdateDate(s1.split("~")[18]); } catch (ArrayIndexOutOfBoundsException arrex) { c.setLastUpdateDate(""); } lCust.add(c); } } for (Customer c : lCust) { Customer cc = Ebean.find(Customer.class, c.getId()); if (cc != null) { cc = c; Ebean.update(cc); } System.out.print(c.getId()); System.out.print(" | "); System.out.print(c.getNama()); System.out.print(" | "); System.out.print(c.getShipto()); System.out.print(" | "); System.out.print(c.getNpwp()); System.out.print(" | "); System.out.print(c.getNamaWajibPajak()); System.out.println(); } } catch (IOException ex) { Logger.getLogger(TestReadCustData.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.yhspy.zbartest.StringUtils.java
/** * Encodes the given string into a sequence of bytes using the ISO-8859-1 charset, storing the result into a new * byte array.//ww w. jav a 2 s. c o m * * @param string * the String to encode, may be {@code null} * @return encoded bytes, or {@code null} if the input string was {@code null} * @throws NullPointerException * Thrown if {@link Charsets#ISO_8859_1} is not initialized, which should never happen since it is * required by the Java platform specification. * @since As of 1.7, throws {@link NullPointerException} instead of UnsupportedEncodingException * @see <a href="http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a> * @see #getBytesUnchecked(String, String) */ public static byte[] getBytesIso8859_1(final String string) { return getBytes(string, Charsets.ISO_8859_1); }
From source file:at.bitfire.ical4android.TaskTest.java
public void testCharsets() throws IOException, InvalidCalendarException { Task t = parseCalendar("latin1.ics", Charsets.ISO_8859_1); assertEquals("", t.summary); t = parseCalendar("utf8.ics", null); assertEquals(" ", t.summary); assertEquals("?", t.location); }
From source file:com.anrisoftware.prefdialog.csvimportdialog.panelproperties.panelproperties.CsvPanelPropertiesModule.java
@SuppressWarnings("deprecation") @Provides//w w w.j a v a2 s . c o m @Singleton @Named("charsetDefaults") Collection<Charset> getCharsetDefaults() { List<Charset> list = new ArrayList<Charset>(); list.add(Charsets.UTF_8); list.add(Charsets.UTF_16); list.add(Charsets.UTF_16BE); list.add(Charsets.UTF_16LE); list.add(Charsets.US_ASCII); list.add(Charsets.ISO_8859_1); return list; }
From source file:at.bitfire.ical4android.EventTest.java
public void testCharsets() throws IOException, InvalidCalendarException { Event e = parseCalendar("latin1.ics", Charsets.ISO_8859_1); assertEquals("", e.summary); e = parseCalendar("utf8.ics", null); assertEquals(" ", e.summary); assertEquals("?", e.location); }
From source file:com.andrewkroh.cisco.xmlservices.HttpTestServerHandler.java
public void setResponse(Object ciscoJaxbObject) { // Marshal object to XML: String objectAsXml = XmlMarshaller.marshalToXml(ciscoJaxbObject); // Build the content of the response body: byte[] bodyContent = objectAsXml.toString().getBytes(Charsets.ISO_8859_1); ByteBuf bodyContentByteBuf = Unpooled.wrappedBuffer(bodyContent); // Build the HTTP response: FullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, bodyContentByteBuf); response.headers().set(HttpHeaders.Names.CACHE_CONTROL, Arrays.asList(HttpHeaders.Values.MUST_REVALIDATE, HttpHeaders.Values.NO_STORE)); response.headers().set(HttpHeaders.Names.CONNECTION, HttpHeaders.Values.CLOSE); response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "text/html"); response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, bodyContent.length); httpResponseRef.set(response);/*w ww.j a va 2 s. c o m*/ }
From source file:com.antsdb.saltedfish.server.mysql.MysqlServerHandler.java
public MysqlServerHandler(SaltedFish fish) { this.fish = fish; packetEncoder = new PacketEncoder(); this.decoder = Codecs.ISO8859; this.packetEncoder.setCodec(Charsets.ISO_8859_1, MYSQL_CHARSET_NAME_binary); }
From source file:com.zimbra.cs.mailbox.Metadata.java
public Metadata(String encoded, Integer associatedItemId) throws MailServiceException { this.associatedItemId = associatedItemId; if (Strings.isNullOrEmpty(encoded)) { map = new HashMap<Object, Object>(); return;//from w ww . j ava 2s .c o m } try { try { map = (Map) BEncoding.decode(encoded); return; } catch (BEncodingException be) { // Bug 87718 in some instances, it appears that an encoded string is getting corrupted by being // treated at some point as if the bytes were ISO-8859-1 instead of UTF-8. Try again with this reversed. // If this works, the internal lengths will have gotten corrected, so there is a fair chance this has // correctly identified what happened. if (be.getCause() != null && be.getCause() instanceof NumberFormatException) { String fixedUpEncoded = new String(encoded.getBytes(Charsets.ISO_8859_1), Charsets.UTF_8); try { map = (Map) BEncoding.decode(fixedUpEncoded); return; } catch (Exception e) { } } throw be; } } catch (BEncodingException e) { try { map = BlobMetaData.decodeRecursive(encoded, associatedItemId); return; } catch (BlobMetaDataEncodingException e1) { } throw MailServiceException.INVALID_METADATA(encoded, e); } finally { if (map != null && map.containsKey(FN_MD_VERSION)) { try { map.remove(FN_MD_VERSION); } catch (Exception e) { } } } }
From source file:com.antsdb.saltedfish.server.mysql.MysqlServerHandler.java
private void resetCharset() throws Exception { if (this.charset != getSession().getProtocolCharset()) { // reset encoder and decoder String name = getSession().getProtocolCharset(); if (name.equals("latin1")) { this.decoder = Codecs.ISO8859; this.packetEncoder.setCodec(Charsets.ISO_8859_1, MYSQL_CHARSET_NAME_binary); } else if (name.equals("cp1250")) { this.decoder = Codecs.ISO8859; this.packetEncoder.setCodec(Charsets.ISO_8859_1, MYSQL_CHARSET_NAME_binary); } else if (name.equals("utf8")) { this.decoder = Codecs.UTF8; this.packetEncoder.setCodec(Charsets.UTF_8, MYSQL_CHARSET_NAME_utf8); } else if (name.equals("utf8mb4")) { this.decoder = Codecs.UTF8; this.packetEncoder.setCodec(Charsets.UTF_8, MYSQL_CHARSET_NAME_utf8); } else {/* w w w . j a v a 2s . c o m*/ throw new Exception("unknown charset: " + name); } this.charset = name; } }
From source file:com.yhspy.zbartest.StringUtils.java
/** * Constructs a new <code>String</code> by decoding the specified array of bytes using the ISO-8859-1 charset. * * @param bytes// www . ja v a 2s. c o m * The bytes to be decoded into characters, may be {@code null} * @return A new <code>String</code> decoded from the specified array of bytes using the ISO-8859-1 charset, or * {@code null} if the input byte array was {@code null}. * @throws NullPointerException * Thrown if {@link Charsets#ISO_8859_1} is not initialized, which should never happen since it is * required by the Java platform specification. * @since As of 1.7, throws {@link NullPointerException} instead of UnsupportedEncodingException */ public static String newStringIso8859_1(final byte[] bytes) { return new String(bytes, Charsets.ISO_8859_1); }