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:carolina.pegaLatLong.LatLong.java

private List<InformacoesTxt> carregaRetorna(String path) throws FileNotFoundException, IOException {
    List<InformacoesTxt> listaInfo = new ArrayList<>();

    //String caminho = "externfiles\\emitente3.txt";
    FileInputStream file = new FileInputStream(path);
    InputStreamReader input = new InputStreamReader(file, java.nio.charset.StandardCharsets.ISO_8859_1);
    BufferedReader br = new BufferedReader(input);
    String pega;//from   w  w  w  .j a  va 2  s  . co  m
    String mostra = "";
    System.err.println(mostra);
    int cont = 0;
    // Nome do Emitente,CNPJ,IE,Endereo,Bairro,CEP,Cidade,UF,Pais,
    while ((pega = br.readLine()) != null) {
        if (cont > 0) {
            String neew = LatLong.removerAcentos(pega.toLowerCase());
            String vet[] = neew.split(";");
            InformacoesTxt info = new InformacoesTxt();
            info.setEndereco(vet[0]);
            info.setCep(vet[1]);
            info.setBairro(vet[2]);
            info.setCidade(vet[3]);
            info.setUf(vet[4]);
            info.setPais(vet[5]);
            listaInfo.add(info);
        }
        cont++;
    }

    return listaInfo;
}

From source file:org.codice.alliance.nsili.source.NsiliSource.java

/**
 * Obtains the IOR string from a local file.
 *///from ww  w  .ja  v  a2s . c om
private void getIorStringFromLocalDisk() {
    try (InputStream inputStream = new FileInputStream(iorUrl.substring(7))) {
        iorString = IOUtils.toString(inputStream, StandardCharsets.ISO_8859_1.name());
    } catch (IOException e) {
        LOGGER.error("{} : Unable to process IOR String.", id, e);
    }
}

From source file:org.codice.alliance.nsili.source.NsiliSource.java

/**
 * Uses the SecureClientCxfFactory to obtain the IOR string from the provided URL via HTTP(S).
 *//* w  w  w . j a va 2  s. com*/
private void getIorStringFromHttpSource() {
    createClientFactory();
    Nsili nsili = factory.getClient();

    try (InputStream inputStream = nsili.getIorFile()) {
        iorString = IOUtils.toString(inputStream, StandardCharsets.ISO_8859_1.name());
        //Remove leading/trailing whitespace as the CORBA init can't handle that.
        iorString = iorString.trim();
    } catch (IOException e) {
        LOGGER.error("{} : Unable to process IOR String. {}", id, e.getMessage());
        LOGGER.debug("{} : Unable to process IOR String.", id, e);
    } catch (Exception e) {
        LOGGER.warn("{} : Error retrieving IOR file for {}. {}", id, iorUrl, e.getMessage());
        LOGGER.debug("{} : Error retrieving IOR file for {}.", id, iorUrl, e);
    }
}

From source file:org.eclipse.smarthome.binding.homematic.internal.communicator.virtual.DisplayTextVirtualDatapoint.java

/**
 * Encodes the given text for the display.
 *//*from  w w  w  . ja v a  2s . c  om*/
private String encodeText(String text) {
    final byte[] bytes = text.getBytes(StandardCharsets.ISO_8859_1);
    StringBuilder sb = new StringBuilder(bytes.length * 2);
    for (byte b : bytes) {
        sb.append("0x");
        String hexValue = String.format("%02x", b);
        sb.append(replaceMap.containsKey(hexValue) ? replaceMap.get(hexValue) : hexValue);
        sb.append(",");
    }
    sb.setLength(sb.length() - 1);
    return sb.toString();
}

From source file:net.sourceforge.jwbf.core.actions.HttpActionClient.java

private static String toISO8859(String toEncode) {
    byte[] array = StandardCharsets.ISO_8859_1.encode(toEncode).array();
    String encoded = new String(array, StandardCharsets.UTF_8);
    return logIfDifferent(toEncode, encoded, "\"{}\" was encoded to \"{}\"; because only iso8859 is supported");
}

From source file:org.mycore.datamodel.ifs.MCRAudioVideoExtender.java

/**
 * Helper method that connects to the given URL and returns the response as
 * a String/*from w  w w.  jav a  2 s  .c  o m*/
 * 
 * @param url
 *            the URL to connect to
 * @return the response content as a String
 */
protected String getMetadata(String url) throws MCRPersistenceException {
    try {
        URLConnection connection = getConnection(url);
        connection.setConnectTimeout(getConnectTimeout());
        String contentType = connection.getContentType();
        Charset charset = StandardCharsets.ISO_8859_1; //defined by RFC 2616 (sec 3.7.1)
        if (contentType != null) {
            MediaType mediaType = MediaType.parse(contentType);
            mediaType.charset().or(StandardCharsets.ISO_8859_1);
        }
        ByteArrayOutputStream out = new ByteArrayOutputStream(1024);
        forwardData(connection, out);

        return new String(out.toByteArray(), charset);
    } catch (IOException exc) {
        String msg = "Could not get metadata from Audio/Video Store URL: " + url;
        throw new MCRPersistenceException(msg, exc);
    }
}

From source file:org.codice.alliance.nsili.source.NsiliSource.java

/**
 * Uses FTPClient to obtain the IOR string from the provided URL via FTP.
 *//*  w  w w  .j av  a 2 s  .c  o m*/
private void getIorStringFromFtpSource() {
    URI uri = null;
    try {
        uri = new URI(iorUrl);
    } catch (URISyntaxException e) {
        LOGGER.error("{} : Invalid URL specified for IOR string: {} {}", id, iorUrl, e.getMessage());
        LOGGER.debug("{} : Invalid URL specified for IOR string: {}", id, iorUrl, e);
    }

    FTPClient ftpClient = new FTPClient();
    try {
        if (uri.getPort() > 0) {
            ftpClient.connect(uri.getHost(), uri.getPort());
        } else {
            ftpClient.connect(uri.getHost());
        }

        if (!ftpClient.login(serverUsername, serverPassword)) {
            LOGGER.error("{} : FTP server log in unsuccessful.", id);
        } else {
            int timeoutMsec = clientTimeout * 1000;
            ftpClient.setConnectTimeout(timeoutMsec);
            ftpClient.setControlKeepAliveReplyTimeout(timeoutMsec);
            ftpClient.setDataTimeout(timeoutMsec);

            ftpClient.enterLocalPassiveMode();
            ftpClient.setFileType(FTP.BINARY_FILE_TYPE);

            InputStream inputStream = ftpClient.retrieveFileStream(uri.getPath());

            iorString = IOUtils.toString(inputStream, StandardCharsets.ISO_8859_1.name());
            //Remove leading/trailing whitespace as the CORBA init can't handle that.
            iorString = iorString.trim();
        }
    } catch (Exception e) {
        LOGGER.warn("{} : Error retrieving IOR file for {}. {}", id, iorUrl, e.getMessage());
        LOGGER.debug("{} : Error retrieving IOR file for {}.", id, iorUrl, e);
    }
}

From source file:org.pshdl.model.simulation.codegenerator.CCodeGenerator.java

public static int hash(final String str) {
    int hash = (-2128831035);
    final byte[] bytes = str.getBytes(StandardCharsets.ISO_8859_1);
    for (final byte b : bytes) {
        {//from   w  w w . ja va2s.  c o  m
            int _bitwiseXor = (hash ^ b);
            hash = _bitwiseXor;
            hash = (hash * 16777619);
        }
    }
    return hash;
}

From source file:com.mirth.connect.plugins.httpauth.digest.DigestAuthenticator.java

/**
 * Calculates the MD5 digest for all objects passed in, concatenated with ':'. InputStreams will
 * be read in and updated directly via a byte buffer. Any other object will be converted to a
 * String updated with the equivalent ISO-8859-1 representation.
 *//* w ww .  j  av  a 2s  .c  om*/
private String digest(Object... parts) throws NoSuchAlgorithmException, IOException {
    MessageDigest md = MessageDigest.getInstance("MD5");

    for (int i = 0; i < parts.length; i++) {
        if (parts[i] instanceof InputStream) {
            InputStream is = (InputStream) parts[i];
            byte[] buffer = new byte[1024];
            int len;
            while ((len = IOUtils.read(is, buffer, 0, buffer.length)) > 0) {
                md.update(buffer, 0, len);
            }
        } else if (parts[i] instanceof byte[]) {
            md.update((byte[]) parts[i]);
        } else {
            md.update(String.valueOf(parts[i]).getBytes(StandardCharsets.ISO_8859_1));
        }

        if (i < parts.length - 1) {
            md.update((byte) ':');
        }
    }

    return TypeUtil.toString(md.digest(), 16);
}

From source file:net.sf.jabref.gui.IconTheme.java

/**
 * Read a typical java property url into a Map. Currently doesn't support escaping
 * of the '=' character - it simply looks for the first '=' to determine where the key ends.
 * Both the key and the value is trimmed for whitespace at the ends.
 *
 * @param url    The URL to read information from.
 * @param prefix A String to prefix to all values read. Can represent e.g. the directory
 *               where icon files are to be found.
 * @return A Map containing all key-value pairs found.
 *//*  ww w. j  a  va  2 s .  c o  m*/
// FIXME: prefix can be removed?!
private static Map<String, String> readIconThemeFile(URL url, String prefix) {
    Objects.requireNonNull(url, "url");
    Objects.requireNonNull(prefix, "prefix");

    Map<String, String> result = new HashMap<>();

    try (BufferedReader in = new BufferedReader(
            new InputStreamReader(url.openStream(), StandardCharsets.ISO_8859_1))) {
        String line;
        while ((line = in.readLine()) != null) {
            if (!line.contains("=")) {
                continue;
            }

            int index = line.indexOf('=');
            String key = line.substring(0, index).trim();
            String value = prefix + line.substring(index + 1).trim();
            result.put(key, value);
        }
    } catch (IOException e) {
        LOGGER.warn("Unable to read default icon theme.", e);
    }
    return result;
}