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:it.unibo.alchemist.test.TestInSimulator.java
@SafeVarargs private static <T> void runSimulation(final String relativeFilePath, final double finalTime, final Consumer<Environment<Object>>... checkProcedures) throws InstantiationException, IllegalAccessException, InvocationTargetException, ClassNotFoundException, SAXException, IOException, ParserConfigurationException, InterruptedException, ExecutionException { final Resource res = XTEXT.getResource(URI.createURI("classpath:/simulations/" + relativeFilePath), true); final IGenerator generator = INJECTOR.getInstance(IGenerator.class); final InMemoryFileSystemAccess fsa = INJECTOR.getInstance(InMemoryFileSystemAccess.class); generator.doGenerate(res, fsa);//from w w w . jav a2s . c om final Collection<CharSequence> files = fsa.getTextFiles().values(); if (files.size() != 1) { fail(); } final ByteArrayInputStream strIS = new ByteArrayInputStream( files.stream().findFirst().get().toString().getBytes(Charsets.UTF_8)); final Environment<Object> env = EnvironmentBuilder.build(strIS).get().getEnvironment(); final Simulation<Object> sim = new Engine<>(env, new DoubleTime(finalTime)); sim.addCommand(new StateCommand<>().run().build()); /* * Use this thread: intercepts failures. */ sim.run(); Arrays.stream(checkProcedures).forEachOrdered(p -> p.accept(env)); }
From source file:com.netflix.spinnaker.clouddriver.artifacts.bitbucket.BitbucketArtifactCredentialsTest.java
private void runTestCase(WireMockServer server, BitbucketArtifactAccount account, Function<MappingBuilder, MappingBuilder> expectedAuth) throws IOException { BitbucketArtifactCredentials credentials = new BitbucketArtifactCredentials(account, okHttpClient); Artifact artifact = Artifact.builder().reference(server.baseUrl() + DOWNLOAD_PATH).version("master") .type("bitbucket/file").build(); prepareServer(server, expectedAuth); assertThat(credentials.download(artifact)) .hasSameContentAs(new ByteArrayInputStream(FILE_CONTENTS.getBytes(Charsets.UTF_8))); assertThat(server.findUnmatchedRequests().getRequests()).isEmpty(); }
From source file:de.fhg.iais.asc.oai.localwriter.RepositoryWriter.java
private void writeSipToRepository(String sip) { File setDir = new File(this.rootDir, this.currentSpec); String filename = this.currentId; int colon = filename.indexOf(':'); if (colon > -1) { filename = filename.substring(colon + 1); }// w w w . ja v a 2s.co m filename = makeFilenameFilesystemCompatible(filename); File file = new File(setDir, filename + ".xml"); try { FileUtils.write(file, sip, Charsets.UTF_8); } catch (IOException e) { throw new DbcException(e); } }
From source file:com.github.scizeron.jidr.maven.plugin.JidrPackageApp.java
@Override public void execute() throws MojoExecutionException { InputStream input = null;/*w w w . java2 s . com*/ FileOutputStream output = null; if ("pom".equals(this.project.getPackaging())) { getLog().info("Skip execute on " + this.project.getPackaging() + " project."); return; } final String outputDirname = this.project.getBuild().getDirectory() + File.separator + "distrib"; final String libOutputDir = outputDirname + File.separator + "lib"; final String appOutputDir = outputDirname + File.separator + "app"; final String confOutputDir = outputDirname + File.separator + "conf"; final String binOutputDir = outputDirname + File.separator + "bin"; try { new File(libOutputDir).mkdirs(); new File(appOutputDir).mkdirs(); new File(binOutputDir).mkdirs(); new File(confOutputDir).mkdirs(); File outputFile = new File(binOutputDir + File.separator + APP_SH_FILE); output = new FileOutputStream(outputFile); input = JidrPackageApp.class.getClassLoader().getResourceAsStream(APP_SH_FILE); final LineIterator lineIterator = IOUtils.lineIterator(input, Charsets.UTF_8); while (lineIterator.hasNext()) { output.write((lineIterator.nextLine() + "\n").getBytes()); } output.close(); getLog().info(String.format("Create \"%s\" in %s.", APP_SH_FILE, binOutputDir)); outputFile = new File(confOutputDir + File.separator + APP_CFG_FILE); output = new FileOutputStream(outputFile); output.write(new String("APP_ARTIFACT=" + project.getArtifactId() + "\n").getBytes()); output.write(new String("APP_PACKAGING=" + project.getPackaging() + "\n").getBytes()); output.write(new String("APP_VERSION=" + project.getVersion()).getBytes()); getLog().info(String.format("Create \"%s\" in %s.", APP_CFG_FILE, confOutputDir)); // si un repertoire src/main/bin est present dans le projet, le contenu // sera copie dans binOutputDir addExtraFiles(this.project.getBasedir().getAbsolutePath() + "/src/main/bin", binOutputDir); // si un repertoire src/main/conf est present dans le projet, le contenu // sera copie dans confOutputDir addExtraFiles(this.project.getBasedir().getAbsolutePath() + "/src/main/conf", confOutputDir); final String artifactFilename = this.project.getBuild().getFinalName() + "." + this.project.getPackaging(); FileUtils.copyFileToDirectory( new File(this.project.getBuild().getDirectory() + File.separator + artifactFilename), new File(appOutputDir)); getLog().info(String.format("Copy \"%s\" to %s.", artifactFilename, appOutputDir)); String distribFilename = this.project.getArtifactId() + "-" + this.project.getVersion() + "-" + classifier + "." + DISTRIB_TYPE; ZipFile distrib = new ZipFile( this.project.getBuild().getDirectory() + File.separator + distribFilename); ZipParameters zipParameters = new ZipParameters(); distrib.addFolder(new File(binOutputDir), zipParameters); distrib.addFolder(new File(appOutputDir), zipParameters); distrib.addFolder(new File(confOutputDir), zipParameters); getLog().info( String.format("Create \"%s\" to %s.", distribFilename, this.project.getBuild().getDirectory())); this.mavenProjectHelper.attachArtifact(this.project, DISTRIB_TYPE, classifier, distrib.getFile()); getLog().info(String.format("Attach \"%s\".", distribFilename)); } catch (Exception exception) { getLog().error(exception); } finally { try { if (output != null) { output.close(); } if (input != null) { input.close(); } } catch (IOException e) { getLog().error(e); } } }
From source file:com.nesscomputing.hbase.TestHBaseSpill.java
@Test public void testSpillOnDequeue() throws Exception { final SpillController spillController = new SpillController("test", hbaseWriterConfig); final HBaseWriter dummyWriter = new HBaseWriter(hbaseWriterConfig, conf, spillController) { @Override/*w ww . j a va 2 s . c om*/ protected HTable connectHTable() throws IOException { throw new IOException("oops"); } }; final Put data = new Put("row".getBytes(Charsets.UTF_8)); data.add("family".getBytes(Charsets.UTF_8), "qualifier".getBytes(Charsets.UTF_8), "Hello, World".getBytes(Charsets.UTF_8)); for (int i = 0; i < queueLength; i++) { dummyWriter.write(data); Assert.assertEquals(0L, spillController.getSpillsOk()); Assert.assertEquals(0L, spillController.getSpillsFailed()); Assert.assertEquals(i + 1, dummyWriter.getQueueLength()); } Assert.assertEquals(0, spillController.getOpsDeqSpilled()); dummyWriter.runLoop(); Assert.assertEquals(queueLength, spillController.getOpsDeqSpilled()); Assert.assertEquals(1L, spillController.getSpillsOk()); }
From source file:com.netflix.spinnaker.clouddriver.artifacts.helm.HelmArtifactCredentialsTest.java
private void runTestCase(WireMockServer server, HelmArtifactAccount account, Function<MappingBuilder, MappingBuilder> expectedAuth) throws IOException { HelmArtifactCredentials credentials = new HelmArtifactCredentials(account, okHttpClient); Artifact artifact = Artifact.builder().name(CHART_NAME).version(CHART_VERSION).type("helm/chart").build(); prepareServer(server, expectedAuth); assertThat(credentials.download(artifact)) .hasSameContentAs(new ByteArrayInputStream(FILE_CONTENTS.getBytes(Charsets.UTF_8))); assertThat(server.findUnmatchedRequests().getRequests()).isEmpty(); }
From source file:com.vilt.minium.jasmine.MiniumJasmineTestRunner.java
private Object getVal(JsVariable jsVariable, Class<?> clazz, Object object) { try {//from w ww . j ava 2 s . co m if (StringUtils.isNotEmpty(jsVariable.resource())) { Resource resource = resourceLoader.getResource(jsVariable.resource()); checkState(resource.exists() && resource.isReadable()); if (clazz == String.class) { InputStream is = resource.getInputStream(); try { return IOUtils.toString(is, Charsets.UTF_8.name()); } finally { IOUtils.closeQuietly(is); } } else { Object val = parseJson(rhinoContext, resource); checkState(clazz.isAssignableFrom(val.getClass())); return val; } } else { return object; } } catch (IOException e) { throw propagate(e); } catch (ParseException e) { throw propagate(e); } }
From source file:ai.grakn.engine.tasks.manager.redisqueue.RedisTaskStorage.java
@Override public Boolean updateState(TaskState state) { try (Jedis jedis = redis.getResource(); Context ignore = updateTimer.time()) { String key = encodeKey.apply(state.getId().getValue()); LOG.debug("Updating state {}", key); String value = new String(Base64.getEncoder().encode(SerializationUtils.serialize(state)), Charsets.UTF_8); String status = jedis.setex(key, 60 * 60/*expire time in seconds*/, value); return status.equalsIgnoreCase("OK"); }//from ww w . j a v a 2 s. c om }
From source file:com.giacomodrago.immediatecrypt.aes.AESFacadeImpl.java
protected ParametersWithIV createDecryptionParameters(String password, String salt, byte[] iv) { byte[] passwordBytes = password.getBytes(Charsets.UTF_8); byte[] saltBytes = salt.getBytes(Charsets.UTF_8); PKCS5S1ParametersGenerator keyGenerator = new PKCS5S1ParametersGenerator(new SHA512Digest()); keyGenerator.init(passwordBytes, saltBytes, PBE_ITERATION_COUNT); KeyParameter params = (KeyParameter) keyGenerator.generateDerivedParameters(KEY_SIZE); return new ParametersWithIV(params, iv); }
From source file:com.cedarsoft.serialization.serializers.stax.mate.DateTimeSerializerTest.java
@Test public void testWrite100() throws IOException, SAXException { byte[] serialized = getSerializer() .serializeToByteArray(new DateTime(2001, 1, 1, 1, 1, 1, 1, zoneRule.getZone())); AssertUtils.assertXMLEquals(new String(serialized, Charsets.UTF_8).trim(), "<dateTime xmlns=\"http://www.joda.org/time/dateTime/1.0.0\">20010101T010101.001-0500</dateTime>"); DateTime deserialized = getSerializer().deserialize(new ByteArrayInputStream(serialized)); assertEqualsDateTime(deserialized, new DateTime(2001, 1, 1, 1, 1, 1, 1, zoneRule.getZone())); assertEquals("America/New_York", zoneRule.getZone().getID()); assertEquals("-05:00", deserialized.getZone().getID()); }