Example usage for java.nio.charset StandardCharsets US_ASCII

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

Introduction

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

Prototype

Charset US_ASCII

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

Click Source Link

Document

Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.

Usage

From source file:com.github.gcauchis.scalablepress4j.api.AbstractRestApi.java

/**
 * Sets the basic auth.//from   ww w. j  av a  2  s  .  c  o m
 *
 * @param basicAuth the new basic auth
 */
public void setBasicAuth(String basicAuth) {
    this.basicAuth = basicAuth;
    if (basicAuth != null) {
        basicAuthHttp = "Basic "
                + new String(Base64.encodeBase64(basicAuth.getBytes(StandardCharsets.US_ASCII)));
    } else {
        basicAuthHttp = null;
    }
}

From source file:gobblin.tunnel.TestTunnelWithArbitraryTCPTraffic.java

private static String readFromSocket(SocketChannel client) throws IOException {
    ByteBuffer readBuf = ByteBuffer.allocate(256);
    LOG.info("Reading from client");
    client.read(readBuf);//  w  ww  .  j  ava2 s  .c  o  m
    readBuf.flip();
    return StandardCharsets.US_ASCII.decode(readBuf).toString();
}

From source file:edu.ksu.cis.santos.mdcf.dms.test.SymbolTableTest.java

void assertEquals(final File expected, final File result) throws Exception {
    final List<String> expectedLines = Files.readLines(expected, StandardCharsets.US_ASCII);
    final List<String> resultLines = Files.readLines(result, StandardCharsets.US_ASCII);

    assertThat(resultLines).isEqualTo(expectedLines);
}

From source file:com.turo.pushy.apns.AuthenticationToken.java

public AuthenticationToken(final ApnsSigningKey signingKey, final Date issuedAt)
        throws NoSuchAlgorithmException, InvalidKeyException, SignatureException {
    this.header = new AuthenticationTokenHeader(signingKey.getKeyId());
    this.claims = new AuthenticationTokenClaims(signingKey.getTeamId(), issuedAt);

    final String headerJson = GSON.toJson(this.header);
    final String claimsJson = GSON.toJson(this.claims);

    final StringBuilder payloadBuilder = new StringBuilder();
    payloadBuilder.append(Base64.encodeBase64URLSafeString(headerJson.getBytes(StandardCharsets.US_ASCII)));
    payloadBuilder.append('.');
    payloadBuilder.append(Base64.encodeBase64URLSafeString(claimsJson.getBytes(StandardCharsets.US_ASCII)));

    {//from   ww  w  . j  ava2  s .  com
        final Signature signature = Signature.getInstance(ApnsKey.APNS_SIGNATURE_ALGORITHM);
        signature.initSign(signingKey);
        signature.update(payloadBuilder.toString().getBytes(StandardCharsets.US_ASCII));

        this.signatureBytes = signature.sign();
    }

    payloadBuilder.append('.');
    payloadBuilder.append(Base64.encodeBase64URLSafeString(this.signatureBytes));

    this.base64EncodedToken = payloadBuilder.toString();
}

From source file:org.sonar.scanner.scan.filesystem.MetadataGeneratorTest.java

private DefaultInputFile createInputFileWithMetadata(Path baseDir, String relativePath) {
    DefaultInputFile inputFile = new TestInputFileBuilder("struts", relativePath).setModuleBaseDir(baseDir)
            .build();/*from www .  jav  a2 s  . com*/
    generator.setMetadata(inputFile, StandardCharsets.US_ASCII);
    return inputFile;
}

From source file:csv.sorting.PrepareWeatherData.java

private static Stream<CsvMappingResult<csv.model.LocalWeatherData>> getLocalWeatherData(Path path) {
    return Parsers.LocalWeatherDataParser().readFromFile(path, StandardCharsets.US_ASCII);
}

From source file:io.undertow.server.handlers.ChunkedRequestNotConsumedTestCase.java

@Test
public void testChunkedRequestNotConsumed() throws IOException {
    HttpPost post = new HttpPost(DefaultServer.getDefaultServerURL() + "/path");
    TestHttpClient client = new TestHttpClient();
    try {//from   ww  w  .ja  va2 s  .  c  o  m
        final Random random = new Random();
        final int seed = random.nextInt();
        System.out.print("Using Seed " + seed);
        random.setSeed(seed);

        for (int i = 0; i < 3; ++i) {
            post.setEntity(new StringEntity("") {
                @Override
                public long getContentLength() {
                    return -1;
                }

                @Override
                public boolean isChunked() {
                    return true;
                }

                @Override
                public void writeTo(OutputStream outstream) throws IOException {
                    outstream.flush();
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {

                    }
                    outstream.write(MESSAGE.getBytes(StandardCharsets.US_ASCII));
                }
            });
            HttpResponse result = client.execute(post);
            Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
            HttpClientUtils.readResponse(result);
        }
    } finally {

        client.getConnectionManager().shutdown();
    }
}

From source file:patientlinkage.Util.Util.java

public static boolean[][][] encodeCobinationAsJAMIA4Criteria(String[][] data1, int[][] properties_bytes) {
    //12, 11, 9, 8
    assert data1[0].length == properties_bytes[0].length;
    boolean[][][] ret = new boolean[data1.length][properties_bytes.length][];

    for (int i = 0; i < data1.length; i++) {
        for (int j = 0; j < properties_bytes.length; j++) {
            String temp = "";
            for (int k = 0; k < properties_bytes[j].length; k++) {
                temp += resizeString(data1[i][k], properties_bytes[j][k]);
            }//from  w w w. jav a 2  s. c o m
            ret[i][j] = bytes2boolean(temp.getBytes(StandardCharsets.US_ASCII));
        }
    }

    return ret;
}

From source file:com.joyent.manta.http.EncryptedHttpHelperTest.java

/**
 * Builds a fully mocked {@link EncryptionHttpHelper} that is setup to
 * be configured for one cipher/mode and executes requests in another
 * cipher/mode.//from www.  j  a v a  2s . c  om
 */
private static EncryptionHttpHelper fakeEncryptionHttpHelper(String path) throws Exception {
    MantaConnectionContext connectionContext = mock(MantaConnectionContext.class);

    StandardConfigContext config = new StandardConfigContext();

    SupportedCipherDetails cipherDetails = AesCbcCipherDetails.INSTANCE_192_BIT;

    config.setClientEncryptionEnabled(true)
            .setEncryptionPrivateKeyBytes(SecretKeyUtils.generate(cipherDetails).getEncoded())
            .setEncryptionAlgorithm(cipherDetails.getCipherId());

    EncryptionHttpHelper httpHelper = new EncryptionHttpHelper(connectionContext,
            new MantaHttpRequestFactory(UnitTestConstants.UNIT_TEST_URL), config);

    URI uri = URI.create(DEFAULT_MANTA_URL + "/" + path);

    CloseableHttpResponse fakeResponse = mock(CloseableHttpResponse.class);
    StatusLine statusLine = new BasicStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_OK, "OK");

    SupportedCipherDetails objectCipherDetails = AesGcmCipherDetails.INSTANCE_128_BIT;

    Header[] headers = new Header[] {
            // Notice this is a different cipher than the one set in config
            new BasicHeader(MantaHttpHeaders.ENCRYPTION_CIPHER, objectCipherDetails.getCipherId()) };

    when(fakeResponse.getAllHeaders()).thenReturn(headers);
    when(fakeResponse.getStatusLine()).thenReturn(statusLine);

    BasicHttpEntity fakeEntity = new BasicHttpEntity();
    InputStream source = IOUtils.toInputStream("I'm a stream", StandardCharsets.US_ASCII);
    EofSensorInputStream stream = new EofSensorInputStream(source, null);
    fakeEntity.setContent(stream);
    when(fakeResponse.getEntity()).thenReturn(fakeEntity);

    when(connectionContext.getHttpClient()).thenReturn(new FakeCloseableHttpClient(fakeResponse));

    return httpHelper;
}

From source file:csv.sorting.PrepareWeatherData.java

private static Stream<csv.model.Station> getStations(Path path) {
    return Parsers.StationParser().readFromFile(path, StandardCharsets.US_ASCII).filter(x -> x.isValid())
            .map(x -> x.getResult());
}