Example usage for java.nio.charset StandardCharsets ISO_8859_1

List of usage examples for java.nio.charset StandardCharsets ISO_8859_1

Introduction

In this page you can find the example usage for java.nio.charset StandardCharsets ISO_8859_1.

Prototype

Charset ISO_8859_1

To view the source code for java.nio.charset StandardCharsets ISO_8859_1.

Click Source Link

Document

ISO Latin Alphabet No.

Usage

From source file:org.sonar.batch.report.SourcePublisherTest.java

@Test
public void publishTestSource() throws Exception {
    FileUtils.write(sourceFile, "1\n2\n3\n4\n", StandardCharsets.ISO_8859_1);
    sampleFile.setQualifier(Qualifiers.UNIT_TEST_FILE);

    publisher.publish(writer);//w  w  w.  j av  a2  s  . com

    File out = writer.getSourceFile(2);
    assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("1\n2\n3\n4\n");
}

From source file:org.eclipse.rcptt.internal.testrail.APIClient.java

private void setUpHeaders(HttpUriRequest request) {
    String credentials = username + ":" + password;
    String encodedCredentials = Base64.encode(credentials.getBytes(StandardCharsets.ISO_8859_1));
    String authorizationHeader = "Basic " + new String(encodedCredentials);
    request.setHeader(HttpHeaders.AUTHORIZATION, authorizationHeader);

    String contentTypeHeader = "application/json";
    request.addHeader(HttpHeaders.CONTENT_TYPE, contentTypeHeader);
}

From source file:org.zanata.adapter.PropertiesLatinOneAdapterTest.java

@Test
public void testTranslatedPropertiesDocument() throws Exception {
    TranslationsResource tResource = new TranslationsResource();

    addTranslation(tResource, "line1", "Founde metalkcta", ContentState.Approved);
    addTranslation(tResource, "line2", "Tbade metalkcta", ContentState.Translated);
    addTranslation(tResource, "line3", "Kbade metalkcta", ContentState.NeedReview);

    File latin1EncodedFile = createTempPropertiesFile(StandardCharsets.ISO_8859_1);
    Resource resource = adapter.parseDocumentFile(latin1EncodedFile.toURI(), LocaleId.EN, Optional.absent());
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

    adapter.writeTranslatedFile(outputStream, null, resource, tResource, "ru", Optional.absent());

    // \u00C0 is the escaped unicode form of 
    assertThat(toLatin1String(outputStream))
            .isEqualTo("line1=\\u00C0Founde metalkcta\n" + "line2=\\u00C0Tbade metalkcta\n" + "line3=\n");
}

From source file:org.springframework.http.converter.FormHttpMessageConverterTests.java

@Test
public void readForm() throws Exception {
    String body = "name+1=value+1&name+2=value+2%2B1&name+2=value+2%2B2&name+3";
    MockHttpInputMessage inputMessage = new MockHttpInputMessage(body.getBytes(StandardCharsets.ISO_8859_1));
    inputMessage.getHeaders()//www . j  av  a 2 s. co  m
            .setContentType(new MediaType("application", "x-www-form-urlencoded", StandardCharsets.ISO_8859_1));
    MultiValueMap<String, String> result = this.converter.read(null, inputMessage);

    assertEquals("Invalid result", 3, result.size());
    assertEquals("Invalid result", "value 1", result.getFirst("name 1"));
    List<String> values = result.get("name 2");
    assertEquals("Invalid result", 2, values.size());
    assertEquals("Invalid result", "value 2+1", values.get(0));
    assertEquals("Invalid result", "value 2+2", values.get(1));
    assertNull("Invalid result", result.getFirst("name 3"));
}

From source file:org.sonar.scanner.report.SourcePublisherTest.java

@Test
public void publishSourceWithLastLineNotEmpty() throws Exception {
    FileUtils.write(sourceFile, "1\n2\n3\n4\n5", StandardCharsets.ISO_8859_1);

    publisher.publish(writer);//from   w  w  w . j  a  va  2 s. c o m

    File out = writer.getSourceFile(inputFile.batchId());
    assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("1\n2\n3\n4\n5");
}

From source file:org.sonar.batch.report.SourcePublisherTest.java

@Test
public void publishSourceWithLastLineNotEmpty() throws Exception {
    FileUtils.write(sourceFile, "1\n2\n3\n4\n5", StandardCharsets.ISO_8859_1);

    publisher.publish(writer);//from   w  w w .jav  a 2  s  . c o m

    File out = writer.getSourceFile(2);
    assertThat(FileUtils.readFileToString(out, StandardCharsets.UTF_8)).isEqualTo("1\n2\n3\n4\n5");
}

From source file:com.torchmind.stockpile.server.controller.v1.BlacklistController.java

/**
 * Checks an IP address against the blacklist.
 *
 * @param address an address.//from w  w  w  . j a va 2 s. c  om
 * @return a blacklist result.
 */
@Nonnull
private BlacklistResult checkAddress(@Nonnull String address) {
    List<String> addressParts = Splitter.on('.').splitToList(address);

    for (int i = (addressParts.size() - 1); i >= 1; --i) {
        String currentAddress = Joiner.on('.').join(addressParts.subList(0, i)) + ".*";
        String hash = Hashing.sha1().hashString(currentAddress, StandardCharsets.ISO_8859_1).toString();

        if (this.hashes.contains(hash)) {
            return new BlacklistResult(currentAddress, true);
        }
    }

    return new BlacklistResult(address, false);
}

From source file:org.apache.hc.client5.http.impl.auth.TestBasicScheme.java

@Test
public void testBasicAuthenticationWith88591Chars() throws Exception {
    final int[] germanChars = { 0xE4, 0x2D, 0xF6, 0x2D, 0xFc };
    final StringBuilder buffer = new StringBuilder();
    for (final int germanChar : germanChars) {
        buffer.append((char) germanChar);
    }/*from  www.  j av a 2s  . c o  m*/

    final HttpHost host = new HttpHost("somehost", 80);
    final AuthScope authScope = new AuthScope(host, "some realm", null);
    final UsernamePasswordCredentials creds = new UsernamePasswordCredentials("dh",
            buffer.toString().toCharArray());
    final BasicCredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(authScope, creds);
    final BasicScheme authscheme = new BasicScheme(StandardCharsets.ISO_8859_1);

    Assert.assertTrue(authscheme.isResponseReady(host, credentialsProvider, null));
    final HttpRequest request = new BasicHttpRequest("GET", "/");
    final String authResponse = authscheme.generateAuthResponse(host, request, null);
    Assert.assertEquals("Basic ZGg65C32Lfw=", authResponse);
}

From source file:edu.unc.lib.dl.admin.controller.ExportController.java

@RequestMapping(value = "{pid}", method = RequestMethod.GET)
public void export(@PathVariable("pid") String pid, HttpServletRequest request, HttpServletResponse response)
        throws IOException {
    String filename = pid.replace(":", "_") + ".csv";
    response.addHeader("Content-Disposition", "attachment; filename=\"" + filename + "\"");
    response.addHeader("Content-Type", "text/csv");

    SearchRequest searchRequest = generateSearchRequest(request, searchStateFactory.createSearchState());

    SearchState searchState = searchRequest.getSearchState();
    searchState.setResultFields(Arrays.asList(SearchFieldKeys.ID.name(), SearchFieldKeys.TITLE.name(),
            SearchFieldKeys.RESOURCE_TYPE.name(), SearchFieldKeys.ANCESTOR_IDS.name(),
            SearchFieldKeys.STATUS.name(), SearchFieldKeys.DATASTREAM.name(),
            SearchFieldKeys.ANCESTOR_PATH.name(), SearchFieldKeys.CONTENT_MODEL.name(),
            SearchFieldKeys.DATE_ADDED.name(), SearchFieldKeys.DATE_UPDATED.name(),
            SearchFieldKeys.LABEL.name()));
    searchState.setSortType("export");
    searchState.setRowsPerPage(searchSettings.maxPerPage);

    BriefObjectMetadata container = queryLayer.addSelectedContainer(pid, searchState, false);
    SearchResultResponse resultResponse = queryLayer.getSearchResults(searchRequest);

    List<BriefObjectMetadata> objects = resultResponse.getResultList();
    objects.add(0, container);//  ww  w . j  av  a2 s .c  om
    queryLayer.getChildrenCounts(objects, searchRequest);

    try (ServletOutputStream out = response.getOutputStream()) {
        Writer writer = new BufferedWriter(new OutputStreamWriter(out, StandardCharsets.ISO_8859_1));

        try (CSVPrinter printer = CSVFormat.EXCEL.print(writer)) {
            printHeaders(printer);

            for (BriefObjectMetadata object : objects) {
                printObject(printer, object);
            }
        }
    }
}

From source file:de.pixida.logtest.automatondefinitions.JsonAutomatonDefinitionTest.java

@Test
public void testWeAreTolerantWhenSourceFileHasInvalidEncoding() throws JSONException, IOException {
    final JSONObject config = SomeTestAutomaton.getRawConfigJson();
    config.getJSONArray("nodes").getJSONObject(0).put("id", ""); // Chose UTF-8 multibyte character
    final File rewrittenConfig = this.testFolder.newFile();
    FileUtils.writeStringToFile(rewrittenConfig, config.toString(), StandardCharsets.ISO_8859_1);
    this.loadAutomatonDefinitionFromFile(rewrittenConfig);
}