Example usage for org.apache.commons.lang CharEncoding ISO_8859_1

List of usage examples for org.apache.commons.lang CharEncoding ISO_8859_1

Introduction

In this page you can find the example usage for org.apache.commons.lang CharEncoding ISO_8859_1.

Prototype

String ISO_8859_1

To view the source code for org.apache.commons.lang CharEncoding ISO_8859_1.

Click Source Link

Document

ISO Latin Alphabet #1, also known as ISO-LATIN-1.

Usage

From source file:com.cmcc.util.StringUtils.java

/**
 * Encodes the given string into a sequence of bytes using the ISO-8859-1 charset, storing the result into a new
 * byte array./*  w  w w . j  a va  2s . c  om*/
 * 
 * @param string
 *            the String to encode, may be <code>null</code>
 * @return encoded bytes, or <code>null</code> if the input string was <code>null</code>
 * @throws IllegalStateException
 *             Thrown when the charset is missing, which should be never according the the Java specification.
 * @see <a href="http://download.oracle.com/javase/1.5.0/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
 * @see #getBytesUnchecked(String, String)
 */
public static byte[] getBytesIso8859_1(String string) {
    return StringUtils.getBytesUnchecked(string, CharEncoding.ISO_8859_1);
}

From source file:com.cmcc.util.StringUtils.java

/**
 * Constructs a new <code>String</code> by decoding the specified array of bytes using the ISO-8859-1 charset.
 * //from w ww.  j  a  v a  2  s. com
 * @param bytes
 *            The bytes to be decoded into characters, may be <code>null</code>
 * @return A new <code>String</code> decoded from the specified array of bytes using the ISO-8859-1 charset,
 *         or <code>null</code> if the input byte array was <code>null</code>.
 * @throws IllegalStateException
 *             Thrown when a {@link UnsupportedEncodingException} is caught, which should never happen since the
 *             charset is required.
 */
public static String newStringIso8859_1(byte[] bytes) {
    return StringUtils.newString(bytes, CharEncoding.ISO_8859_1);
}

From source file:org.eclipse.gyrex.cloud.internal.NodeMetricsReporter.java

@Override
protected IStatus run(final IProgressMonitor monitor) {
    if (monitor.isCanceled()) {
        return Status.CANCEL_STATUS;
    }/*from   w w w. j a va2s . com*/

    try {
        final Properties metrics = new Properties() {
            private static final long serialVersionUID = 1L;

            @Override
            public synchronized Enumeration<Object> keys() {
                return Collections.enumeration(keySet());
            }

            @Override
            public Set<Object> keySet() {
                return new TreeSet<Object>(super.keySet());
            }
        };
        final OperatingSystemMXBean operatingSystemMXBean = ManagementFactory.getOperatingSystemMXBean();
        metrics.setProperty("os.availableProcessors",
                String.valueOf(operatingSystemMXBean.getAvailableProcessors()));
        metrics.setProperty("os.systemLoadAverage",
                String.valueOf(operatingSystemMXBean.getSystemLoadAverage()));
        metrics.setProperty("os.committedVirtualMemorySize",
                getUsingReflection(operatingSystemMXBean, "getCommittedVirtualMemorySize"));
        metrics.setProperty("os.totalSwapSpaceSize",
                getUsingReflection(operatingSystemMXBean, "getTotalSwapSpaceSize"));
        metrics.setProperty("os.freeSwapSpaceSize",
                getUsingReflection(operatingSystemMXBean, "getFreeSwapSpaceSize"));
        metrics.setProperty("os.processCpuTime",
                getUsingReflection(operatingSystemMXBean, "getProcessCpuTime"));
        metrics.setProperty("os.freePhysicalMemorySize",
                getUsingReflection(operatingSystemMXBean, "getFreePhysicalMemorySize"));
        metrics.setProperty("os.totalPhysicalMemorySize",
                getUsingReflection(operatingSystemMXBean, "getTotalPhysicalMemorySize"));
        metrics.setProperty("os.openFileDescriptorCount",
                getUsingReflection(operatingSystemMXBean, "getOpenFileDescriptorCount"));
        metrics.setProperty("os.maxFileDescriptorCount",
                getUsingReflection(operatingSystemMXBean, "getMaxFileDescriptorCount"));

        final MemoryMXBean memoryMXBean = ManagementFactory.getMemoryMXBean();
        final MemoryUsage heapMemoryUsage = memoryMXBean.getHeapMemoryUsage();
        metrics.setProperty("heap.used", String.valueOf(heapMemoryUsage.getUsed()));
        metrics.setProperty("heap.committed", String.valueOf(heapMemoryUsage.getCommitted()));
        metrics.setProperty("heap.max", String.valueOf(heapMemoryUsage.getMax()));
        metrics.setProperty("heap.init", String.valueOf(heapMemoryUsage.getInit()));
        final MemoryUsage nonHeapMemoryUsage = memoryMXBean.getNonHeapMemoryUsage();
        metrics.setProperty("nonHeap.used", String.valueOf(nonHeapMemoryUsage.getUsed()));
        metrics.setProperty("nonHeap.committed", String.valueOf(nonHeapMemoryUsage.getCommitted()));
        metrics.setProperty("nonHeap.max", String.valueOf(nonHeapMemoryUsage.getMax()));
        metrics.setProperty("nonHeap.init", String.valueOf(nonHeapMemoryUsage.getInit()));

        final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
        metrics.setProperty("thread.count", String.valueOf(threadMXBean.getThreadCount()));
        metrics.setProperty("thread.peak", String.valueOf(threadMXBean.getPeakThreadCount()));
        metrics.setProperty("thread.totalStarted", String.valueOf(threadMXBean.getTotalStartedThreadCount()));

        final RuntimeMXBean runtimeMXBean = ManagementFactory.getRuntimeMXBean();
        metrics.setProperty("uptime", String.valueOf(runtimeMXBean.getUptime()));

        final ByteArrayOutputStream out = new ByteArrayOutputStream();
        final NodeInfo nodeInfo = CloudState.getNodeInfo();
        metrics.store(out, String.valueOf(nodeInfo));
        ZooKeeperGate.get().writeRecord(IZooKeeperLayout.PATH_NODES_METRICS.append(nodeInfo.getNodeId()),
                CreateMode.PERSISTENT, out.toByteArray());
        if (CloudDebug.nodeMetrics) {
            LOG.debug("Node metrics reported successfully.{}{}", SystemUtils.LINE_SEPARATOR,
                    new String(out.toByteArray(), CharEncoding.ISO_8859_1));
        }
    } catch (final Exception e) {
        LOG.warn("Failed to update node metrics. {}", e.getMessage());
    } finally {
        // reschedule
        schedule(DELAY);
    }

    return Status.OK_STATUS;
}

From source file:org.gtdfree.Messages.java

public static String getString(String key) {
    if (utf8Convert == null) {
        if (RESOURCE_BUNDLE.containsKey(ENCODING)) {
            try {
                String s = RESOURCE_BUNDLE.getString(ENCODING);
                utf8Convert = s != null && CharEncoding.UTF_8.equalsIgnoreCase(s);
            } catch (MissingResourceException e) {
                // ignore
            }/*from  www . j a  v a2  s.  c  o m*/
        }

        if (utf8Convert == null) {
            utf8Convert = Boolean.FALSE;
        }
    }

    try {
        String message = RESOURCE_BUNDLE.getString(key);

        if (utf8Convert) {
            try {
                // converts scrambled UTF-8 characters withing ISO_8859_1 into proper UTF-8
                message = new String(message.getBytes(CharEncoding.ISO_8859_1), CharEncoding.UTF_8);
            } catch (UnsupportedEncodingException e) {
                //e.printStackTrace();
            }
        }
        return message;
    } catch (MissingResourceException e) {
        return '!' + key + '!';
    }
}

From source file:org.kitodo.production.plugin.opac.pica.OpacResponseHandler.java

String getSessionId() throws UnsupportedEncodingException {
    // TODO HACK/*w  ww . j a  v a 2s . c  om*/
    String sessionIdUrlencoded = URLEncoder.encode(sessionId, CharEncoding.ISO_8859_1);
    if (!this.cookie.equals("")) {
        sessionIdUrlencoded = sessionIdUrlencoded + "/COOKIE="
                + URLEncoder.encode(cookie, CharEncoding.ISO_8859_1);
    }
    return sessionIdUrlencoded;
}

From source file:org.kitodo.production.plugin.opac.pica.Query.java

private void addQuery(String operation, String query, String fieldNumber) {

    // ignore boolean operation for first term
    if (this.queryTermNumber == 0) {
        this.queryUrl = OPERATOR + this.queryTermNumber + "=" + FIRST_OPERATOR;
    } else {/* ww w.j a  va2s  .c o m*/
        this.queryUrl += OPERATOR + this.queryTermNumber + "=" + operation;
    }

    this.queryUrl += FIELD + this.queryTermNumber + "=" + fieldNumber;

    try {
        this.queryUrl += QUERY + this.queryTermNumber + "=" + URLEncoder.encode(query, CharEncoding.ISO_8859_1);
    } catch (Exception e) {
        e.printStackTrace();
    }

    this.queryTermNumber++;
}