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.acciente.oacc.encryptor.jasypt.LegacyJasyptPasswordEncryptor.java

@Override
public boolean checkPassword(final char[] plainPassword, final String encryptedPassword) {
    if (plainPassword == null) {
        return (encryptedPassword == null);
    } else if (encryptedPassword == null) {
        return false;
    }//from  ww  w  . java  2 s .co  m

    return this.digester.matches(getCleanedBytes(plainPassword),
            this.base64.decode(encryptedPassword.getBytes(StandardCharsets.US_ASCII)));
}

From source file:org.apache.tika.parser.microsoft.MSOwnerFileParser.java

/**
 * Extracts owner from MS temp file//from   w  w  w.j av a  2s .  c o  m
 */
public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext context)
        throws IOException, SAXException, TikaException {

    XHTMLContentHandler xhtml = new XHTMLContentHandler(handler, metadata);
    xhtml.startDocument();
    byte[] asciiNameBytes = new byte[ASCII_CHUNK_LENGTH];
    IOUtils.readFully(stream, asciiNameBytes);
    int asciiNameLength = (int) asciiNameBytes[0];//don't need to convert to unsigned int because it can't be that long
    String asciiName = new String(asciiNameBytes, 1, asciiNameLength, StandardCharsets.US_ASCII);
    metadata.set(TikaCoreProperties.MODIFIER, asciiName);

    int unicodeCharLength = stream.read();
    if (unicodeCharLength > 0) {
        stream.read();//zero after the char length
        byte[] unicodeBytes = new byte[unicodeCharLength * 2];
        IOUtils.readFully(stream, unicodeBytes);
        String unicodeName = new String(unicodeBytes, StandardCharsets.UTF_16LE);
        metadata.set(TikaCoreProperties.MODIFIER, unicodeName);
    }
    xhtml.endDocument();
}

From source file:com.linecorp.bot.spring.boot.LineBotAutoConfiguration.java

@Bean
@ConditionalOnWebApplication//from w ww.j  a v  a2s . c  o  m
public LineSignatureValidator lineSignatureValidator() {
    return new LineSignatureValidator(lineBotProperties.getChannelSecret().getBytes(StandardCharsets.US_ASCII));
}

From source file:com.acciente.oacc.encryptor.jasypt.PasswordEncoderDecoder.java

/**
 * Encodes an identifying header, the parameters used to generate the Jasypt digest, and the Jasypt digest into a
 * single "self-contained" password that contains enough information for future comparisons.
 *
 * @param algorithm     the algorithm used to generate the digest.
 * @param iterations    the number of iterations used to generate the digest.
 * @param saltSizeBytes the salt size bytes used to generate the digest.
 * @param digest        the digest itself.
 * @return a fully-encoded password ready for persistent storage.
 *//*from w  w w. j a v  a2s  . co  m*/
String encode(String algorithm, int iterations, int saltSizeBytes, byte[] digest) {
    // setup array of values to encode -- to help ensure same param sequence in encode and decode logic
    final Object[] decodedPasswordArray = new Object[DECODED_PASSWORD_ARRAY_COUNT];
    decodedPasswordArray[DECODED_PASSWORD_ARRAY_ALGORITHM] = algorithm;
    decodedPasswordArray[DECODED_PASSWORD_ARRAY_ITERATIONS] = iterations;
    decodedPasswordArray[DECODED_PASSWORD_ARRAY_SALT_SIZE_BYTES] = saltSizeBytes;
    decodedPasswordArray[DECODED_PASSWORD_ARRAY_DIGEST] = new String(base64.encode(digest),
            StandardCharsets.US_ASCII);

    final StringBuilder encodedPassword = new StringBuilder(128).append(MARKER);
    for (int i = 0; i < DECODED_PASSWORD_ARRAY_COUNT - 1; i++) {
        encodedPassword.append(decodedPasswordArray[i]);
        encodedPassword.append(PARAM_DELIMITER);
    }
    // encode last param without the delimiter
    encodedPassword.append(decodedPasswordArray[DECODED_PASSWORD_ARRAY_COUNT - 1]);

    return encodedPassword.toString();
}

From source file:org.osgp.adapter.protocol.dlms.domain.commands.GetFirmwareVersionCommandExecutor.java

@Override
public String execute(final ClientConnection conn, final DlmsDevice device, final Void useless)
        throws ProtocolAdapterException {

    LOGGER.info(//w  ww . j  a v  a 2 s .c o m
            "Retrieving firmware version by issuing get request for class id: {}, obis code: {}, attribute id: {}",
            CLASS_ID, OBIS_CODE, ATTRIBUTE_ID);

    final AttributeAddress firmwareVersionValue = new AttributeAddress(CLASS_ID, OBIS_CODE, ATTRIBUTE_ID);

    List<GetResult> getResultList;
    try {
        getResultList = conn.get(firmwareVersionValue);
    } catch (IOException | TimeoutException e) {
        throw new ConnectionException(e);
    }

    if (getResultList.isEmpty()) {
        throw new ProtocolAdapterException("No GetResult received while retrieving firmware version.");
    }

    if (getResultList.size() > 1) {
        throw new ProtocolAdapterException(
                "Expected 1 GetResult while retrieving firmware version, got " + getResultList.size());
    }

    final GetResult result = getResultList.get(0);
    final DataObject resultData = result.resultData();

    if (!resultData.isByteArray()) {
        throw new ProtocolAdapterException(
                "Unexpected value returned by meter while retrieving firmware version.");
    }

    return new String((byte[]) resultData.value(), StandardCharsets.US_ASCII);
}

From source file:org.apache.cloudstack.storage.configdrive.ConfigDriveBuilder.java

/**
 * Writes a String encoded in base 64 to a file in the given folder.
 * The content will be decoded and then written to the file. Be aware that we will overwrite the content of the file if it already exists.
 * Moreover, the content will must be encoded in {@link  StandardCharsets#US_ASCII} before it is encoded in base 64.
 *//*from   w  ww . j  a va2 s.  com*/
public static File base64StringToFile(String encodedIsoData, String folder, String fileName)
        throws IOException {
    byte[] decoded = Base64.decodeBase64(encodedIsoData.getBytes(StandardCharsets.US_ASCII));
    Path destPath = Paths.get(folder, fileName);
    try {
        Files.createDirectories(destPath.getParent());
    } catch (final IOException e) {
        LOG.warn("Exception hit while trying to recreate directory: " + destPath.getParent().toString());
    }
    return Files.write(destPath, decoded).toFile();
}

From source file:com.joyent.manta.client.crypto.EncryptingEntityTest.java

@Test(expectedExceptions = MantaClientEncryptionException.class)
public void throwsWithTooLargeContentLength() {
    SupportedCipherDetails cipherDetails = AesGcmCipherDetails.INSTANCE_128_BIT;
    byte[] keyBytes = SecretKeyUtils.generate(cipherDetails).getEncoded();

    SecretKey key = SecretKeyUtils.loadKey(Arrays.copyOfRange(keyBytes, 2, 10), cipherDetails);

    ExposedStringEntity stringEntity = new ExposedStringEntity("boo", StandardCharsets.US_ASCII);

    EncryptingEntity entity = new EncryptingEntity(key, cipherDetails, stringEntity);
}

From source file:io.druid.segment.writeout.WriteOutBytesTest.java

private void verifyContents(WriteOutBytes writeOutBytes, String expected) throws IOException {
    Assert.assertEquals(expected, IOUtils.toString(writeOutBytes.asInputStream(), StandardCharsets.US_ASCII));
    ByteBuffer bb = ByteBuffer.allocate((int) writeOutBytes.size());
    writeOutBytes.readFully(0, bb);//www .j  a v a 2  s. c  om
    bb.flip();
    Assert.assertEquals(expected, StringUtils.fromUtf8(bb));
}

From source file:nl.salp.warcraft4j.dev.casc.model.ListFile.java

private static Map<String, Long> parseFile(Path listFile) throws IOException {
    Map<String, Long> listfile = new HashMap<>();
    try (DataReader reader = new FileDataReader(listFile)) {
        while (reader.hasRemaining()) {
            String line = reader.readNext(DataTypeFactory.getStringLine()).trim();
            if (isNotEmpty(line)) {
                byte[] data = line.replace('/', '\\').toUpperCase().getBytes(StandardCharsets.US_ASCII);
                long hash = JenkinsHash.hashLittle2(data, data.length);
                listfile.put(line, hash);
            }//from www.  j ava2  s  . c  o m
        }
    }
    return listfile;
}

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

@Test
public void should_detect_charset_from_BOM() {
    Path basedir = Paths.get("src/test/resources/org/sonar/scanner/scan/filesystem/");

    assertThat(createInputFileWithMetadata(basedir.resolve("without_BOM.txt")).charset())
            .isEqualTo(StandardCharsets.US_ASCII);
    assertThat(createInputFileWithMetadata(basedir.resolve("UTF-8.txt")).charset())
            .isEqualTo(StandardCharsets.UTF_8);
    assertThat(createInputFileWithMetadata(basedir.resolve("UTF-16BE.txt")).charset())
            .isEqualTo(StandardCharsets.UTF_16BE);
    assertThat(createInputFileWithMetadata(basedir.resolve("UTF-16LE.txt")).charset())
            .isEqualTo(StandardCharsets.UTF_16LE);
    assertThat(createInputFileWithMetadata(basedir.resolve("UTF-32BE.txt")).charset())
            .isEqualTo(MetadataGenerator.UTF_32BE);
    assertThat(createInputFileWithMetadata(basedir.resolve("UTF-32LE.txt")).charset())
            .isEqualTo(MetadataGenerator.UTF_32LE);
}