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.seleritycorp.common.base.http.client.FileHttpClientTest.java
@Test public void testExecuteGetOk() throws Exception { Path tmpFile = this.createTempFile(); this.writeFile(tmpFile, "foo\nbar"); replayAll();/*from w ww .j a v a 2s. com*/ HttpClient httpClient = createFileHttpClient(); HttpGet method = new HttpGet(tmpFile.toUri()); org.apache.http.HttpResponse response = httpClient.execute(method); HttpEntity entity = response.getEntity(); verifyAll(); assertThat(response.getStatusLine().getProtocolVersion().getProtocol()).isEqualTo("FILE"); assertThat(response.getStatusLine().getStatusCode()).isEqualTo(200); assertThat(response.getStatusLine().getReasonPhrase()).isEqualTo("OK"); assertThat(entity).isNotNull(); assertThat(entity.getContentEncoding()).isNull(); assertThat(entity.getContentType()).isNull(); String body = EntityUtils.toString(entity, StandardCharsets.UTF_8); assertThat(body).isEqualTo("foo\nbar"); }
From source file:com.vsct.dt.strowgr.admin.repository.consul.ConsulReaderTest.java
@Test public void should_throw_exception_when_status_out_of_range_200_299() { for (int status = 100; status < 600; status++) { if (status >= 200 && status < 300) continue; // skip // given//w w w . ja v a2 s . com HttpResponse httpResponse = mock(HttpResponse.class); when(httpResponse.getStatusLine()) .thenReturn(new BasicStatusLine(new ProtocolVersion("http1.1", 1, 1), status, "")); BasicHttpEntity givenHttpEntity = new BasicHttpEntity(); givenHttpEntity.setContent(new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8))); when(httpResponse.getEntity()).thenReturn(givenHttpEntity); // test try { new ConsulReader(null).parseHttpResponse(httpResponse, this::getHttpEntity); // check fail("can't reach this point for status " + status); } catch (ClientProtocolException e) { // check assertThat(e.getMessage()).contains(String.valueOf(status)); } } }
From source file:com.cognifide.aet.job.common.ArtifactDAOMock.java
@Override public String saveArtifact(DBKey dbKey, String data) { savedArtifactDatas.add(data.getBytes(StandardCharsets.UTF_8)); return ""; }
From source file:io.wcm.devops.conga.plugins.sling.fileheader.ProvisioningFileHeaderTest.java
@Test public void testApply() throws Exception { File file = new File("target/generation-test/fileHeader.txt"); FileUtils.copyFile(new File(getClass().getResource("/validProvisioning.txt").toURI()), file); List<String> lines = ImmutableList.of("Der Jodelkaiser", "aus dem Oetztal", "ist wieder daheim."); FileHeaderContext context = new FileHeaderContext().commentLines(lines); FileContext fileContext = new FileContext().file(file); assertTrue(underTest.accepts(fileContext, context)); underTest.apply(fileContext, context); assertTrue(StringUtils.contains(FileUtils.readFileToString(file, StandardCharsets.UTF_8), "# Der Jodelkaiser\n# aus dem Oetztal\n# ist wieder daheim.\n")); FileHeaderContext extractContext = underTest.extract(fileContext); assertEquals(lines, extractContext.getCommentLines()); file.delete();//w w w . java2s. c o m }
From source file:io.github.swagger2markup.internal.component.UriSchemeComponentTest.java
@Test public void testUriSchemeComponent() throws URISyntaxException { Swagger swagger = new Swagger().host("http://localhost").basePath("/v2"); swagger.addScheme(Scheme.HTTP);/*from w ww. j a va2 s . c o m*/ swagger.addScheme(Scheme.HTTPS); Swagger2MarkupConverter.Context context = createContext(); MarkupDocBuilder markupDocBuilder = context.createMarkupDocBuilder(); markupDocBuilder = new UriSchemeComponent(context).apply(markupDocBuilder, UriSchemeComponent.parameters(swagger, OverviewDocument.SECTION_TITLE_LEVEL)); markupDocBuilder.writeToFileWithoutExtension(outputDirectory, StandardCharsets.UTF_8); Path expectedFile = getExpectedFile(COMPONENT_NAME); DiffUtils.assertThatFileIsEqual(expectedFile, outputDirectory, getReportName(COMPONENT_NAME)); }
From source file:org.eclipse.rcptt.internal.testrail.APIClient.java
public String sendPostRequest(String endpoint, String params) { HttpPost request = new HttpPost(url + endpoint); // Full Unicode support was added in TestRail 2.0, // so we use ISO-8859-1 by default, // but if Unicode is needed, it could be enabled in preferences if (useUnicode) { request.setEntity(new StringEntity(params, StandardCharsets.UTF_8)); } else {/*from ww w .jav a 2 s. c om*/ request.setEntity(new StringEntity(params, StandardCharsets.ISO_8859_1)); } TestRailPlugin.logInfo(MessageFormat.format(Messages.APIClient_GeneratedRequest, params)); return sendRequest(request); }
From source file:cherry.foundation.download.DownloadTemplateTest.java
@Test public void testDownload00() throws IOException { HttpServletResponse response = createMock(); LocalDateTime timestamp = LocalDateTime.now(); String ts = DateTimeFormat.forPattern("yyyyMMddHHmmss").print(timestamp); DownloadAction action = new DownloadAction() { @Override//w ww . ja v a 2s . c om public long doDownload(OutputStream stream) throws IOException { return 123L; } }; downloadOperation.download(response, "text/csv", StandardCharsets.UTF_8, "test_{0}.csv", timestamp, action); verify(response).setContentType("text/csv"); verify(response).setCharacterEncoding("UTF-8"); verify(response).setHeader("Content-Disposition", "attachment; filename=\"test_" + ts + ".csv\""); }
From source file:com.muk.services.commerce.CryptoServiceImpl.java
@Override public String encrypt(String value) { final byte[] result = encrypt(value.getBytes(StandardCharsets.UTF_8)); return encode(result); }
From source file:hrytsenko.gscripts.App.java
private static void executeCustomScript(GroovyShell shell, Path script) { Path scriptFilename = script.getFileName(); LOGGER.info("Execute: {}.", scriptFilename); try (BufferedReader reader = Files.newBufferedReader(script, StandardCharsets.UTF_8)) { shell.evaluate(reader);//from w w w . j av a2 s . c o m } catch (IOException exception) { throw new AppException(String.format("Cannot execute script %s.", scriptFilename), exception); } }
From source file:org.italiangrid.storm.webdav.fs.attrs.DefaultExtendedFileAttributesHelper.java
@Override public void setExtendedFileAttribute(File f, String attributeName, String attributeValue) throws IOException { Assert.notNull(f);/* w ww .ja v a2 s . c om*/ Assert.hasText(attributeName); UserDefinedFileAttributeView faView = Files.getFileAttributeView(f.toPath(), UserDefinedFileAttributeView.class); if (faView == null) { throw new IOException("UserDefinedFileAttributeView not supported on file " + f.getAbsolutePath()); } faView.write(attributeName, StandardCharsets.UTF_8.encode(attributeValue)); }