List of usage examples for java.nio.charset StandardCharsets UTF_8
Charset UTF_8
To view the source code for java.nio.charset StandardCharsets UTF_8.
Click Source Link
From source file:com.synopsys.integration.blackduck.codelocation.bdioupload.UploadCallable.java
@Override public UploadOutput call() { try {//from ww w .j a va 2s .com String jsonPayload; try { jsonPayload = FileUtils.readFileToString(uploadTarget.getUploadFile(), StandardCharsets.UTF_8); } catch (IOException e) { return UploadOutput.FAILURE(uploadTarget.getCodeLocationName(), "Failed to initially read file: " + uploadTarget.getUploadFile().getAbsolutePath() + " because " + e.getMessage(), e); } String uri = blackDuckService.getUri(BlackDuckService.BOMIMPORT_PATH); Request request = RequestFactory.createCommonPostRequestBuilder(jsonPayload).uri(uri) .mimeType(uploadTarget.getMediaType()).build(); try (Response response = blackDuckService.execute(request)) { String responseString = response.getContentString(); return UploadOutput.SUCCESS(uploadTarget.getCodeLocationName(), responseString); } catch (IOException e) { return UploadOutput.FAILURE(uploadTarget.getCodeLocationName(), e.getMessage(), e); } } catch (Exception e) { return UploadOutput.FAILURE(uploadTarget.getCodeLocationName(), "Failed to upload file: " + uploadTarget.getUploadFile().getAbsolutePath() + " because " + e.getMessage(), e); } }
From source file:com.lexicalintelligence.search.SearchRequest.java
public SearchResponse execute() { Reader reader = null;/* ww w . j a v a 2s . co m*/ SearchResponse searchResponse = new SearchResponse(true); try { HttpResponse response = client.getHttpClient() .execute(new HttpGet(client.getUrl() + PATH + "?prefix=" + URLEncoder.encode(query, "UTF-8"))); reader = new InputStreamReader(response.getEntity().getContent(), StandardCharsets.UTF_8); List<String> items = client.getObjectMapper().readValue(reader, new TypeReference<List<String>>() { }); searchResponse.setItems(items); } catch (Exception e) { searchResponse = new SearchResponse(false); log.error(e); } finally { try { reader.close(); } catch (Exception e) { log.error(e); } } return searchResponse; }
From source file:aiai.apps.sign_env.SignEnv.java
@Override public void run(String... args) throws IOException, GeneralSecurityException { if (args.length < 2) { System.out.println("SignEnv <file with env string> <private key file>"); return;/*w w w .jav a 2s. c o m*/ } File srcFile = new File(args[0]); if (!srcFile.exists()) { System.out.println("Source file with environment doesn't exist"); return; } File privateKeyFile = new File(args[1]); if (!privateKeyFile.exists()) { System.out.println("Private key file wasn't found. File: " + args[1]); return; } String privateKeyStr = FileUtils.readFileToString(privateKeyFile, StandardCharsets.UTF_8); PrivateKey privateKey = SecUtils.getPrivateKey(privateKeyStr); // Process String env = FileUtils.readFileToString(srcFile, StandardCharsets.UTF_8).trim(); String signature = SecUtils.getSignature(env, privateKey, true); System.out.println("Env:\n" + env); System.out.println("\nSignature:\n" + signature); }
From source file:io.apicurio.hub.api.bitbucket.BitbucketSourceConnectorTest.java
@BeforeClass public static void globalSetUp() { File credsFile = new File(".bitbucket"); if (!credsFile.isFile()) { return;/*ww w.j av a 2s. c o m*/ } System.out.println("Loading Bitbucket credentials from: " + credsFile.getAbsolutePath()); try (Reader reader = new FileReader(credsFile)) { Properties props = new Properties(); props.load(reader); String userPass = props.getProperty("username") + ":" + props.getProperty("password"); basicAuth = Base64.encodeBase64String(userPass.getBytes(StandardCharsets.UTF_8)); } catch (IOException e) { e.printStackTrace(); throw new RuntimeException(e); } }
From source file:nu.yona.server.rest.StandardResourcesController.java
@RequestMapping(value = "/.well-known/apple-app-site-association", method = RequestMethod.GET) @ResponseBody//from w w w. j a va 2s . c o m public ResponseEntity<byte[]> getAppleAppSiteAssociation() { Context ctx = ThymeleafUtil.createContext(); ctx.setVariable("appleAppId", yonaProperties.getAppleAppId()); return new ResponseEntity<>( templateEngine.process("apple-app-site-association.json", ctx).getBytes(StandardCharsets.UTF_8), HttpStatus.OK); }
From source file:org.bonitasoft.web.designer.model.JacksonObjectMapper.java
public byte[] toJson(Object object, Class<?> serializationView) throws IOException { // Use UTF8 to accept any character and have platform-independent files. return objectMapper.writerWithView(serializationView).writeValueAsString(object) .getBytes(StandardCharsets.UTF_8); }
From source file:de.elomagic.mag.ConfigurationTest.java
@Test public void testEncryption() throws Exception { Configuration.loadConfiguration(file.toPath()); Assert.assertEquals("secret", Configuration.get(ConfigurationKey.MailReceivePassword)); Configuration.encryptConfiguration(file.toPath()); Properties p = new Properties(); p.load(Files.newReader(file, StandardCharsets.UTF_8)); String value = p.getProperty(ConfigurationKey.MailReceivePassword.getKey()); Assert.assertTrue(SimpleCrypt.isEncryptedValue(value)); Assert.assertEquals("secret", SimpleCrypt.decrypt(value)); }
From source file:joachimeichborn.geotag.io.writer.kml.KmlWriter.java
/** * Create the output KML file containing: * <ul>//www . j a v a 2 s.c o m * <li>placemarks for all positions * <li>a path connecting all positions in chronological order * <li>circles showing the accuracy information for all positions * </ul> * * @throws IOException */ public void write(final Track aTrack, final Path aOutputFile) throws IOException { final String documentTitle = FilenameUtils.removeExtension(aOutputFile.getFileName().toString()); final GeoTagKml kml = createKml(documentTitle, aTrack); try (final Writer kmlWriter = new OutputStreamWriter( new BufferedOutputStream(new FileOutputStream(aOutputFile.toFile())), StandardCharsets.UTF_8)) { kml.marshal(kmlWriter); } logger.fine("Wrote track to " + aOutputFile); }
From source file:com.samczsun.helios.handler.addons.JarLauncher.java
@Override public void run(File file) { JarFile jarFile = null;// ww w . j av a 2s . c om InputStream inputStream = null; try { System.out.println("Loading addon: " + file.getAbsolutePath()); jarFile = new JarFile(file); ZipEntry entry = jarFile.getEntry("addon.json"); if (entry != null) { inputStream = jarFile.getInputStream(entry); JsonObject jsonObject = JsonObject .readFrom(new InputStreamReader(inputStream, StandardCharsets.UTF_8)); String main = jsonObject.get("main").asString(); URL[] url = new URL[] { file.toURI().toURL() }; ClassLoader classLoader = AccessController .doPrivileged((PrivilegedAction<ClassLoader>) () -> new URLClassLoader(url, Helios.class.getClassLoader())); Class<?> clazz = Class.forName(main, true, classLoader); if (Addon.class.isAssignableFrom(clazz)) { Addon addon = Addon.class.cast(clazz.newInstance()); registerAddon(addon.getName(), addon); } else { throw new IllegalArgumentException("Addon main does not extend Addon"); } } else { throw new IllegalArgumentException("No addon.json found"); } } catch (Exception e) { ExceptionHandler.handle(e); } finally { IOUtils.closeQuietly(jarFile); IOUtils.closeQuietly(inputStream); } }
From source file:com.diffplug.gradle.GradleIntegrationTest.java
protected String read(String path) throws IOException { Path target = folder.getRoot().toPath().resolve(path); String content = new String(Files.readAllBytes(target), StandardCharsets.UTF_8); return FileMisc.toUnixNewline(content); }