List of usage examples for org.apache.commons.io Charsets UTF_8
Charset UTF_8
To view the source code for org.apache.commons.io Charsets UTF_8.
Click Source Link
Eight-bit Unicode Transformation Format.
From source file:com.music.tools.HeaderManager.java
public static void main(String[] args) throws Exception { String path = args[0];//from ww w .jav a2 s. com String header = FileUtils.readFileToString(new File(path, "src/main/resources/license/AGPL-3-header.txt"), Charsets.UTF_8); File sourceRoot = new File(path, "src"); System.out.println("Source root is: " + sourceRoot); Collection<File> files = FileUtils.listFiles(sourceRoot, new String[] { "java" }, true); System.out.println("Ammending " + files.size() + " source files"); for (File file : files) { System.out.println("Checking file " + file); String content = FileUtils.readFileToString(file, Charsets.UTF_8); if (content.contains("Copyright")) { System.out.println("Skipping file " + file); continue; } content = header + LS + LS + content; FileUtils.write(file, content); } }
From source file:ch.algotrader.event.TopicEventDumper.java
public static void main(String... args) throws Exception { SingleConnectionFactory jmsActiveMQFactory = new SingleConnectionFactory( new ActiveMQConnectionFactory("tcp://localhost:61616")); jmsActiveMQFactory.afterPropertiesSet(); jmsActiveMQFactory.resetConnection(); ActiveMQTopic topic = new ActiveMQTopic(">"); DefaultMessageListenerContainer messageListenerContainer = new DefaultMessageListenerContainer(); messageListenerContainer.setDestination(topic); messageListenerContainer.setConnectionFactory(jmsActiveMQFactory); messageListenerContainer.setSubscriptionShared(false); messageListenerContainer.setCacheLevel(DefaultMessageListenerContainer.CACHE_CONSUMER); messageListenerContainer.setMessageListener((MessageListener) message -> { try {// ww w. ja va 2 s . co m Destination destination = message.getJMSDestination(); if (message instanceof TextMessage) { TextMessage textMessage = (TextMessage) message; System.out.println(destination + " -> " + textMessage.getText()); } else if (message instanceof BytesMessage) { BytesMessage bytesMessage = (BytesMessage) message; byte[] bytes = new byte[(int) bytesMessage.getBodyLength()]; bytesMessage.readBytes(bytes); System.out.println(destination + " -> " + new String(bytes, Charsets.UTF_8)); } } catch (JMSException ex) { throw new UnrecoverableCoreException(ex); } }); messageListenerContainer.initialize(); messageListenerContainer.start(); System.out.println("Dumping messages from all topics"); Runtime.getRuntime().addShutdownHook(new Thread(messageListenerContainer::stop)); Thread.sleep(Long.MAX_VALUE); }
From source file:com.ikanow.aleph2.enrichment.utils.services.JsScriptEngineTestService.java
/** Entry point * @param args/* w w w .j ava 2s .c o m*/ * @throws IOException */ public static void main(String[] args) throws IOException { if (args.length < 3) { System.out .println("ARGS: <script-file> <input-file> <output-prefix> [{[len: <LEN>], [group: <GROUP>]}]"); } // STEP 1: load script file final String user_script = Files.toString(new File(args[0]), Charsets.UTF_8); // STEP 2: get a stream for the JSON file final InputStream io_stream = new FileInputStream(new File(args[1])); // STEP 3: set up control if applicable Optional<JsonNode> json = Optional.of("").filter(__ -> args.length > 3).map(__ -> args[3]) .map(Lambdas.wrap_u(j -> _mapper.readTree(j))); // STEP 4: set up the various objects final DataBucketBean bucket = Mockito.mock(DataBucketBean.class); final JsScriptEngineService service_under_test = new JsScriptEngineService(); final LinkedList<ObjectNode> emitted = new LinkedList<>(); final LinkedList<JsonNode> grouped = new LinkedList<>(); final LinkedList<JsonNode> externally_emitted = new LinkedList<>(); final IEnrichmentModuleContext context = Mockito.mock(IEnrichmentModuleContext.class, new Answer<Void>() { @SuppressWarnings("unchecked") public Void answer(InvocationOnMock invocation) { try { Object[] args = invocation.getArguments(); if (invocation.getMethod().getName().equals("emitMutableObject")) { final Optional<JsonNode> grouping = (Optional<JsonNode>) args[3]; if (grouping.isPresent()) { grouped.add(grouping.get()); } emitted.add((ObjectNode) args[1]); } else if (invocation.getMethod().getName().equals("externalEmit")) { final DataBucketBean to = (DataBucketBean) args[0]; final Either<JsonNode, Map<String, Object>> out = (Either<JsonNode, Map<String, Object>>) args[1]; externally_emitted .add(((ObjectNode) out.left().value()).put("__a2_bucket", to.full_name())); } } catch (Exception e) { e.printStackTrace(); } return null; } }); final EnrichmentControlMetadataBean control = BeanTemplateUtils.build(EnrichmentControlMetadataBean.class) .with(EnrichmentControlMetadataBean::config, new LinkedHashMap<String, Object>( ImmutableMap.<String, Object>builder().put("script", user_script).build())) .done().get(); service_under_test.onStageInitialize(context, bucket, control, Tuples._2T(ProcessingStage.batch, ProcessingStage.grouping), Optional.empty()); final BeJsonParser json_parser = new BeJsonParser(); // Run the file through final Stream<Tuple2<Long, IBatchRecord>> json_stream = StreamUtils .takeUntil(Stream.generate(() -> json_parser.getNextRecord(io_stream)), i -> null == i) .map(j -> Tuples._2T(0L, new BatchRecord(j))); service_under_test.onObjectBatch(json_stream, json.map(j -> j.get("len")).map(j -> (int) j.asLong(0L)), json.map(j -> j.get("group"))); System.out.println("RESULTS: "); System.out.println("emitted: " + emitted.size()); System.out.println("grouped: " + grouped.size()); System.out.println("externally emitted: " + externally_emitted.size()); Files.write(emitted.stream().map(j -> j.toString()).collect(Collectors.joining(";")), new File(args[2] + "emit.json"), Charsets.UTF_8); Files.write(grouped.stream().map(j -> j.toString()).collect(Collectors.joining(";")), new File(args[2] + "group.json"), Charsets.UTF_8); Files.write(externally_emitted.stream().map(j -> j.toString()).collect(Collectors.joining(";")), new File(args[2] + "external_emit.json"), Charsets.UTF_8); }
From source file:com.opentable.etcd.EtcdServerRule.java
private static String newDiscoveryUrl(int clusterSize) { try {//w w w . ja v a 2 s . c o m return IOUtils.toString(new URL("https://discovery.etcd.io/new?size=" + clusterSize), Charsets.UTF_8); } catch (IOException e) { throw new RuntimeException(e); } }
From source file:backtype.storm.messaging.netty.SaslUtils.java
/** * Encode a password as a base64-encoded char[] array. * //from w ww . ja v a2 s . co m * @param password * as a byte array. * @return password as a char array. */ static char[] encodePassword(byte[] password) { return new String(Base64.encodeBase64(password), Charsets.UTF_8).toCharArray(); }
From source file:com.qatickets.common.ZIPHelper.java
public static byte[] compress(String string) { try {/*from ww w . ja v a2 s.c o m*/ return compress(string.getBytes(Charsets.UTF_8.displayName())); } catch (UnsupportedEncodingException e) { log.error(e); } return null; }
From source file:com.opendoorlogistics.studio.dialogs.AboutBoxDialog.java
private static String info(boolean showLicenses) { // Use own class loader to prevent problems when jar loaded by reflection InputStream is = AboutBoxDialog.class .getResourceAsStream(showLicenses ? "/resources/Licences.html" : "/resources/About.html"); StringWriter writer = new StringWriter(); try {//from w w w. j av a 2s . c om IOUtils.copy(is, writer, Charsets.UTF_8); is.close(); } catch (Throwable e) { } String s = writer.toString(); s = replaceVersionNumberTags(s); return s; }
From source file:com.birbit.jsonapi.TestUtil.java
static String readTestData(String name) throws IOException { return FileUtils.readFileToString(new File("test-data/" + name), Charsets.UTF_8); }
From source file:backtype.storm.messaging.netty.SaslUtils.java
/** * Encode a identifier as a base64-encoded char[] array. * /*from w ww. ja v a 2 s . co m*/ * @param identifier * as a byte array. * @return identifier as a char array. */ static String encodeIdentifier(byte[] identifier) { return new String(Base64.encodeBase64(identifier), Charsets.UTF_8); }
From source file:com.nesscomputing.hbase.spill.TestBinaryConverter.java
@Test public void testSimple() { final Put put = new Put(UUID.randomUUID().toString().getBytes(Charsets.UTF_8)); put.add("family1".getBytes(Charsets.UTF_8), "qualifier1".getBytes(Charsets.UTF_8), System.currentTimeMillis(), "data1".getBytes(Charsets.UTF_8)); put.add("family2".getBytes(Charsets.UTF_8), "qualifier2".getBytes(Charsets.UTF_8), System.currentTimeMillis(), "data2".getBytes(Charsets.UTF_8)); put.add("family3".getBytes(Charsets.UTF_8), "qualifier3".getBytes(Charsets.UTF_8), System.currentTimeMillis(), "data3".getBytes(Charsets.UTF_8)); final byte[] data = new BinaryConverter.PutToBinary().apply(put); final Put put2 = new BinaryConverter.StreamToPut().apply(new ByteArrayInputStream(data)); Assert.assertNotNull(put2);/* w w w . j av a 2 s . c o m*/ Assert.assertArrayEquals(put.getRow(), put2.getRow()); for (final List<KeyValue> entries : put.getFamilyMap().values()) { for (final KeyValue kv : entries) { Assert.assertTrue(put2.has(kv.getFamily(), kv.getQualifier(), kv.getTimestamp(), kv.getValue())); } } for (final byte[] family : put.getFamilyMap().keySet()) { Assert.assertTrue(put2.getFamilyMap().containsKey(family)); } Assert.assertEquals(put.getFamilyMap().size(), put2.getFamilyMap().size()); }