List of usage examples for org.apache.commons.io Charsets US_ASCII
Charset US_ASCII
To view the source code for org.apache.commons.io Charsets US_ASCII.
Click Source Link
Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.
From source file:com.tinspx.util.io.callbacks.SegmentingCallbackTest.java
private static char[] toChars(Charset charset, int len) { checkArgument(len >= 0);// www .jav a 2 s. c o m if (charset == com.google.common.base.Charsets.US_ASCII) { return IOTest.getRandomAsciiChars(RANDOM, len); } else if (charset == com.google.common.base.Charsets.ISO_8859_1) { return IOTest.getRandomISO8859Chars(RANDOM, len); } else { return IOTest.getRandomChars(RANDOM, len); } }
From source file:fi.ilmoeuro.membertrack.TestBase.java
private void initSchema() { try (final InputStream schemaFileStream = ResourceRoot.class.getResourceAsStream(SCHEMA_LIST_FILE)) { if (schemaFileStream == null) { throw new RuntimeException("Schema list not found"); } else {//www. jav a 2 s .c o m for (final String schemaFile : IOUtils.readLines(schemaFileStream, Charsets.UTF_8)) { try (final InputStream sqlStream = ResourceRoot.class.getResourceAsStream(schemaFile)) { if (sqlStream == null) { throw new RuntimeException(String.format("Schema file '%s' not found", schemaFile)); } else { final String sql = IOUtils.toString(sqlStream, Charsets.US_ASCII); for (String part : sql.split(";")) { if (jooq == null) { throw new IllegalStateException("jooq must be initialized"); } else { jooq.execute(part); } } } } } } } catch (IOException ex) { throw new RuntimeException("Couldn't retrieve schema file", ex); } }
From source file:ch.algotrader.hibernate.InMemoryDBTest.java
@After public void cleanup() throws Exception { ResourceDatabasePopulator dbPopulator = new ResourceDatabasePopulator(); dbPopulator.addScript(new ByteArrayResource("DROP ALL OBJECTS".getBytes(Charsets.US_ASCII))); DatabasePopulatorUtils.execute(dbPopulator, EmbeddedTestDB.DATABASE.getDataSource()); if (this.sessionFactory != null) { TransactionSynchronizationManager.unbindResource(EmbeddedTestDB.DATABASE.getSessionFactory()); }// w w w . j av a2 s . c o m if (this.session != null) { if (this.session.isOpen()) { this.session.close(); } } }
From source file:io.github.hebra.elasticsearch.beat.meterbeat.device.dlink.DSPW215.java
@Override public String fetchData() { final String url = config.getBaseurl().concat("/my_cgi.cgi?") .concat(new BigInteger(130, secureRandom).toString(32)); try {/*from w ww . j a va2 s . c o m*/ RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(timeout) .setConnectTimeout(timeout).setConnectionRequestTimeout(timeout).build(); HttpClient client = HttpClientBuilder.create().setConnectionTimeToLive(5, TimeUnit.SECONDS) .setConnectionReuseStrategy(new NoConnectionReuseStrategy()).build(); HttpPost post = new HttpPost(url); post.setConfig(requestConfig); post.setHeader("User-Agent", USER_AGENT); post.setHeader("Accept-Language", "en-US,en;q=0.5"); final List<NameValuePair> urlParameters = new ArrayList<>(); urlParameters.add(new BasicNameValuePair("request", "create_chklst")); post.setEntity(new UrlEncodedFormEntity(urlParameters)); final HttpResponse response = client.execute(post); final String content = IOUtils.toString(response.getEntity().getContent(), Charsets.US_ASCII); EntityUtils.consume(response.getEntity()); return content.split("Meter Watt: ", 2)[1].trim(); } catch (IOException ioEx) { log.error("Timeout when trying to read from {} on {}: {}", config.getName(), config.getBaseurl(), ioEx.getMessage()); } return null; }
From source file:com.tinspx.util.io.callbacks.SegmentingCallbackTest.java
@Test @SuppressWarnings({ "unchecked", "rawtypes", "null" }) public void testInvalidArgs() { DecodingOutputStream d = new DecodingOutputStream(Charsets.US_ASCII.newDecoder()); try {/* w ww . ja v a2 s. c o m*/ SegmentingCallback.create(null); fail(); } catch (NullPointerException ex) { } try { SegmentingCallback.create(d, (ContentListener) null); fail(); } catch (NullPointerException ex) { } try { SegmentingCallback.create(d, (Collection) null); fail(); } catch (NullPointerException ex) { } try { SegmentingCallback.create(d, Content.emptyCallback(), null); fail(); } catch (NullPointerException ex) { } SegmentingCallback s = SegmentingCallback.create(d); assertSame(d, s.decoder()); assertFalse(s.isDecoding()); assertFalse(s.hasError()); assertFalse(s.error().isPresent()); try { s.callbacks().add(null); fail(); } catch (IllegalArgumentException ex) { } try { s.callback(null); fail(); } catch (NullPointerException ex) { } try { s.callbacks(Content.emptyCallback(), null); fail(); } catch (NullPointerException ex) { } assertFalse(s.isDecoding()); ContentTest.AssertCallback ac = new ContentTest.AssertCallback(); s.callback(ac); assertTrue(s.isDecoding()); s.onContentStart(null); s.onContentComplete(null); s.onError(null); try { s.onContent(null, null); fail(); } catch (NullPointerException ex) { } assertTrue(s.isDecoding()); assertFalse(s.hasError()); assertFalse(s.error().isPresent()); s.onContent(ac, ByteBuffer.wrap(new byte[] { (byte) 0xFF })); assertFalse(s.isDecoding()); assertTrue(s.hasError()); assertTrue(s.error().isPresent()); s.onContent(ac, ByteBuffer.wrap(new byte[] { (byte) 0xFF })); assertTrue(d.isEmpty()); ac.start(1); ac.content(0); ac.complete(1); ac.error(2); }
From source file:ch.algotrader.dao.AbstractDaoTest.java
@After public void cleanup() throws Exception { if (this.session != null) { this.session.close(); ResourceDatabasePopulator dbPopulator = new ResourceDatabasePopulator(); dbPopulator.addScript(new ByteArrayResource("TRUNCATE TABLE GenericItem".getBytes(Charsets.US_ASCII))); DatabasePopulatorUtils.execute(dbPopulator, DATABASE.getDataSource()); TransactionSynchronizationManager.unbindResource(DATABASE.getSessionFactory()); }/*from w ww .ja v a 2 s . co m*/ }
From source file:ch.algotrader.cache.CacheTest.java
@AfterClass public static void afterClass() { // cleanup the database ResourceDatabasePopulator dbPopulator = new ResourceDatabasePopulator(); dbPopulator.addScript(new ByteArrayResource("DROP ALL OBJECTS".getBytes(Charsets.US_ASCII))); DatabasePopulatorUtils.execute(dbPopulator, database); context.close();// ww w .j av a2 s . co m net.sf.ehcache.CacheManager ehCacheManager = net.sf.ehcache.CacheManager.getInstance(); ehCacheManager.shutdown(); }
From source file:ch.algotrader.service.LookupServiceTest.java
@Override @After/*from ww w .j av a 2s . c o m*/ public void cleanup() throws Exception { ResourceDatabasePopulator dbPopulator = new ResourceDatabasePopulator(); dbPopulator.addScript(new ByteArrayResource("DROP ALL OBJECTS".getBytes(Charsets.US_ASCII))); DatabasePopulatorUtils.execute(dbPopulator, dataSource); TransactionSynchronizationManager.unbindResource(sessionFactory); if (this.session != null) { if (this.session.isOpen()) { this.session.close(); } } cacheManager.clear(); }
From source file:com.gargoylesoftware.htmlunit.util.EncodingSniffer.java
/** * Extracts an encoding from the specified <tt>Content-Type</tt> value using * <a href="http://ietfreport.isoc.org/idref/draft-abarth-mime-sniff/">the IETF algorithm</a>; if * no encoding is found, this method returns {@code null}. * * @param s the <tt>Content-Type</tt> value to search for an encoding * @return the encoding found in the specified <tt>Content-Type</tt> value, or {@code null} if no * encoding was found/* w w w .j a va2 s .c o m*/ */ static String extractEncodingFromContentType(final String s) { if (s == null) { return null; } final byte[] bytes = s.getBytes(Charsets.US_ASCII); int i; for (i = 0; i < bytes.length; i++) { if (matches(bytes, i, CHARSET_START)) { i += CHARSET_START.length; break; } } if (i == bytes.length) { return null; } while (bytes[i] == 0x09 || bytes[i] == 0x0A || bytes[i] == 0x0C || bytes[i] == 0x0D || bytes[i] == 0x20) { i++; if (i == bytes.length) { return null; } } if (bytes[i] != '=') { return null; } i++; if (i == bytes.length) { return null; } while (bytes[i] == 0x09 || bytes[i] == 0x0A || bytes[i] == 0x0C || bytes[i] == 0x0D || bytes[i] == 0x20) { i++; if (i == bytes.length) { return null; } } if (bytes[i] == '"') { if (bytes.length <= i + 1) { return null; } final int index = ArrayUtils.indexOf(bytes, (byte) '"', i + 1); if (index == -1) { return null; } final String charset = new String(ArrayUtils.subarray(bytes, i + 1, index), Charsets.US_ASCII); return isSupportedCharset(charset) ? charset : null; } if (bytes[i] == '\'') { if (bytes.length <= i + 1) { return null; } final int index = ArrayUtils.indexOf(bytes, (byte) '\'', i + 1); if (index == -1) { return null; } final String charset = new String(ArrayUtils.subarray(bytes, i + 1, index), Charsets.US_ASCII); return isSupportedCharset(charset) ? charset : null; } int end = skipToAnyOf(bytes, i, new byte[] { 0x09, 0x0A, 0x0C, 0x0D, 0x20, 0x3B }); if (end == -1) { end = bytes.length; } final String charset = new String(ArrayUtils.subarray(bytes, i, end), Charsets.US_ASCII); return isSupportedCharset(charset) ? charset : null; }
From source file:com.gargoylesoftware.htmlunit.util.EncodingSniffer.java
/** * Searches the specified XML content for an XML declaration and returns the encoding if found, * otherwise returns {@code null}./* w ww . j a va 2s . c om*/ * * @param bytes the XML content to sniff * @return the encoding of the specified XML content, or {@code null} if it could not be determined */ static String sniffEncodingFromXmlDeclaration(final byte[] bytes) { String encoding = null; if (bytes.length > 5 && XML_DECLARATION_PREFIX[0] == bytes[0] && XML_DECLARATION_PREFIX[1] == bytes[1] && XML_DECLARATION_PREFIX[2] == bytes[2] && XML_DECLARATION_PREFIX[3] == bytes[3] && XML_DECLARATION_PREFIX[4] == bytes[4] && XML_DECLARATION_PREFIX[5] == bytes[5]) { final int index = ArrayUtils.indexOf(bytes, (byte) '?', 2); if (index + 1 < bytes.length && bytes[index + 1] == '>') { final String declaration = new String(bytes, 0, index + 2, Charsets.US_ASCII); int start = declaration.indexOf("encoding"); if (start != -1) { start += 8; char delimiter; outer: while (true) { switch (declaration.charAt(start)) { case '"': case '\'': delimiter = declaration.charAt(start); start = start + 1; break outer; default: start++; } } final int end = declaration.indexOf(delimiter, start); encoding = declaration.substring(start, end); } } } if (encoding != null && !isSupportedCharset(encoding)) { encoding = null; } if (encoding != null && LOG.isDebugEnabled()) { LOG.debug("Encoding found in XML declaration: '" + encoding + "'."); } return encoding; }