Example usage for java.nio.charset Charset defaultCharset

List of usage examples for java.nio.charset Charset defaultCharset

Introduction

In this page you can find the example usage for java.nio.charset Charset defaultCharset.

Prototype

Charset defaultCharset

To view the source code for java.nio.charset Charset defaultCharset.

Click Source Link

Usage

From source file:it.geosolutions.geostore.core.security.password.SecurityUtils.java

/**
 * Converts a char array to a byte array.
 * <p>/*ww w  .  ja v a  2  s  .  c  o m*/
 * This method is unsafe since the charset is not specified, one of 
 * {@link #toBytes(char[], String)} or  {@link #toBytes(char[], Charset)} should be used 
 * instead. When not specified {@link Charset#defaultCharset()} is used.
 * </p>
 */
public static byte[] toBytes(char[] ch) {
    return toBytes(ch, Charset.defaultCharset());
}

From source file:net.es.nsi.common.util.ContentType.java

public static String decode2String(String contentType, InputStream is) throws IOException {
    if (XGZIP.equalsIgnoreCase(contentType)) {
        return IOUtils.toString(new GZIPInputStream(is), Charset.defaultCharset());
    } else {//  w w  w . j  av  a  2 s  . c o  m
        return IOUtils.toString(is, Charset.defaultCharset());
    }
}

From source file:io.fabric8.kubernetes.pipeline.devops.elasticsearch.BaseSendEvent.java

/**
 * Java main to test creating events in elasticsearch.  Set the following ENV VARS to point to a local ES running in OpenShift
 *
 * PIPELINE_ELASTICSEARCH_HOST=elasticsearch.vagrant.f8
 * ELASTICSEARCH_SERVICE_PORT=80// w  ww .  j a  v a  2  s  . c o m
 *
 * @param event to send to elasticsearch
 */
public static void send(DTOSupport event, String type) {

    hudson.model.BuildListener listener = new StreamBuildListener(System.out, Charset.defaultCharset());
    try {
        ObjectMapper mapper = JsonUtils.createObjectMapper();
        String json = mapper.writeValueAsString(event);
        String id = ElasticsearchClient.createEvent(json, type, listener);
        listener.getLogger().println("Added events id: " + id);
    } catch (Exception e) {
        LOG.log(Level.SEVERE, "Error when sending build data: " + event, e);
    }
}

From source file:de.tudarmstadt.lt.utilities.IOUtils.java

public static String readFile(String file) throws FileNotFoundException, IOException {
    return readFile(file, Charset.defaultCharset());
}

From source file:Main.java

/**
 * //ww  w.  j av  a 2  s. c o m
 * @param elementName
 * @param attributeValue
 * @param is
 * @return Collection
 * @throws XMLStreamException
 * @throws FactoryConfigurationError
 * @throws UnsupportedEncodingException
 */
public static Collection<String> getElementValues(final String elementName, final String attributeValue,
        final InputStream is)
        throws XMLStreamException, UnsupportedEncodingException, FactoryConfigurationError {
    final Collection<String> elementValues = new ArrayList<>();
    final XMLEventReader xmlEventReader = XMLInputFactory.newInstance()
            .createXMLEventReader(new InputStreamReader(is, Charset.defaultCharset().name()));
    final StringBuffer characters = new StringBuffer();
    boolean read = false;

    while (xmlEventReader.peek() != null) {
        final XMLEvent event = (XMLEvent) xmlEventReader.next();

        switch (event.getEventType()) {
        case XMLStreamConstants.START_DOCUMENT:
        case XMLStreamConstants.END_DOCUMENT: {
            // Ignore.
            break;
        }
        case XMLStreamConstants.START_ELEMENT: {
            read = elementName.equals(event.asStartElement().getName().getLocalPart());

            if (read && attributeValue != null) {
                read = false;

                for (Iterator<Attribute> iterator = event.asStartElement().getAttributes(); iterator
                        .hasNext();) {
                    Attribute attribute = iterator.next();

                    if (attribute.getValue().equals(attributeValue)) {
                        read = true;
                        break;
                    }
                }
            }

            break;
        }
        case XMLStreamConstants.CHARACTERS: {
            if (read) {
                characters.append(event.asCharacters().getData());
            }
            break;
        }
        case XMLStreamConstants.END_ELEMENT: {
            if (read) {
                elementValues.add(characters.toString());
                characters.setLength(0);
            }

            read = false;
            break;
        }
        default: {
            // Ignore
            break;
        }
        }
    }

    return elementValues;
}

From source file:com.blackducksoftware.integration.hub.detect.util.DetectZipUtil.java

public static void unzip(File zip, File dest) throws IOException {
    unzip(zip, dest, Charset.defaultCharset());
}

From source file:com.siniatech.siniautils.file.PathHelper.java

static public String getFileContents(Path file) throws IOException {
    try (BufferedReader in = newBufferedReader(file, Charset.defaultCharset())) {
        StringBuffer sb = new StringBuffer();
        String line;//from   w  ww.j  a v a2 s. c om
        while ((line = in.readLine()) != null) {
            sb.append(line);
        }
        return sb.toString();
    }
}

From source file:be.i8c.codequality.sonar.plugins.sag.webmethods.flow.sslr.FlowParser.java

public static Parser<Grammar> create() {
    FlowParser.conf = new FlowConfiguration(Charset.defaultCharset());
    return Parser.builder(FlowGrammar.create()).withLexer(FlowLexer.create(FlowParser.conf)).build();
}

From source file:be.i8c.codequality.sonar.plugins.sag.webmethods.flow.sslr.NodeParser.java

public static Parser<Grammar> create() {
    NodeParser.conf = new FlowConfiguration(Charset.defaultCharset());
    return Parser.builder(NodeGrammar.create()).withLexer(FlowLexer.create(NodeParser.conf)).build();
}

From source file:Main.java

/**
 * Use a temporary file to obtain the name of the default system encoding
 * @return name of default system encoding, or null if write failed
 *///from   w  w  w .  j av a 2 s  .c o  m
private static String determineSystemEncoding() {
    File tempFile = null;
    String encoding = null;
    try {
        tempFile = File.createTempFile("gpsprune", null);
        OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(tempFile));
        encoding = getEncoding(writer);
        writer.close();
    } catch (IOException e) {
    } // value stays null
      // Delete temp file
    if (tempFile != null && tempFile.exists()) {
        if (!tempFile.delete()) {
            System.err.println("Cannot delete temp file: " + tempFile.getAbsolutePath());
        }
    }
    // If writing failed (eg permissions) then just ask system for default
    if (encoding == null)
        encoding = Charset.defaultCharset().name();
    return encoding;
}