Example usage for org.apache.commons.codec.binary StringUtils newStringIso8859_1

List of usage examples for org.apache.commons.codec.binary StringUtils newStringIso8859_1

Introduction

In this page you can find the example usage for org.apache.commons.codec.binary StringUtils newStringIso8859_1.

Prototype

public static String newStringIso8859_1(final byte[] bytes) 

Source Link

Document

Constructs a new String by decoding the specified array of bytes using the ISO-8859-1 charset.

Usage

From source file:com.github.trask.sandbox.ec2.Ec2Service.java

private void createKeyPair(String keyName, String privateKeyPath)
        throws FileNotFoundException, JSchException, IOException {

    if (!new File(privateKeyPath).exists()) {
        generateKey(privateKeyPath, keyName);
    }/*from   w  ww.j  a v  a  2s .  c  om*/
    Reader r = new BufferedReader(new StringReader(FileUtils.readFileToString(new File(privateKeyPath))));
    PEMReader pem = new PEMReader(r, new PasswordFinder() {
        public char[] getPassword() {
            // this will get called if the private key is password protected
            // TODO deal with this here/elsewhere?
            throw new PasswordNotSupportedException();
        }
    });
    java.security.KeyPair pair = (java.security.KeyPair) pem.readObject();
    String publicKey = StringUtils.newStringIso8859_1(Base64.encodeBase64(pair.getPublic().getEncoded()));
    deleteKeyPairIfExists(keyName);
    ImportKeyPairRequest request = new ImportKeyPairRequest(keyName, publicKey);
    ec2.importKeyPair(request);
}

From source file:yoyo.framework.standard.shared.commons.codec.StringUtilsTest.java

@Test
public void test() {
    String testee = org.apache.commons.lang3.StringUtils.EMPTY;
    assertThat(StringUtils.getBytesUnchecked(testee, "UTF-8"), is(ArrayUtils.EMPTY_BYTE_ARRAY));
    assertThat(StringUtils.getBytesIso8859_1(testee), is(ArrayUtils.EMPTY_BYTE_ARRAY));
    assertThat(StringUtils.getBytesUsAscii(testee), is(ArrayUtils.EMPTY_BYTE_ARRAY));
    assertThat(StringUtils.getBytesUtf8(testee), is(ArrayUtils.EMPTY_BYTE_ARRAY));
    assertThat(StringUtils.getBytesUtf16(testee), is(ArrayUtils.EMPTY_BYTE_ARRAY));
    assertThat(StringUtils.getBytesUtf16Le(testee), is(ArrayUtils.EMPTY_BYTE_ARRAY));
    assertThat(StringUtils.getBytesUtf16Be(testee), is(ArrayUtils.EMPTY_BYTE_ARRAY));
    assertThat(StringUtils.newString(ArrayUtils.EMPTY_BYTE_ARRAY, "UTF-8"), is(testee));
    assertThat(StringUtils.newStringIso8859_1(ArrayUtils.EMPTY_BYTE_ARRAY), is(testee));
    assertThat(StringUtils.newStringUsAscii(ArrayUtils.EMPTY_BYTE_ARRAY), is(testee));
    assertThat(StringUtils.newStringUtf8(ArrayUtils.EMPTY_BYTE_ARRAY), is(testee));
    assertThat(StringUtils.newStringUtf16(ArrayUtils.EMPTY_BYTE_ARRAY), is(testee));
    assertThat(StringUtils.newStringUtf16Le(ArrayUtils.EMPTY_BYTE_ARRAY), is(testee));
    assertThat(StringUtils.newStringUtf16Be(ArrayUtils.EMPTY_BYTE_ARRAY), is(testee));
}