Example usage for java.nio.charset StandardCharsets UTF_8

List of usage examples for java.nio.charset StandardCharsets UTF_8

Introduction

In this page you can find the example usage for java.nio.charset StandardCharsets UTF_8.

Prototype

Charset UTF_8

To view the source code for java.nio.charset StandardCharsets UTF_8.

Click Source Link

Document

Eight-bit UCS Transformation Format.

Usage

From source file:keepinchecker.utility.EmailUtilities.java

public static void sendScheduledEmail() throws Exception {
    User currentUser = Constants.USER;//ww  w . ja v  a2  s.  c om

    // initialize the email last sent date
    if (currentUser != null && currentUser.getEmailLastSentDate() == 0) {
        setEmailLastSentDate(currentUser);
    }

    if (canEmailBeSent(currentUser)) {
        Email email = createEmail(currentUser);
        String userEmailString = new String(currentUser.getUserEmail(), StandardCharsets.UTF_8);
        String userEmailPassword = new String(currentUser.getUserEmailPassword(), StandardCharsets.UTF_8);
        Mailer mailer = new Mailer("smtp.gmail.com", 587, userEmailString, userEmailPassword,
                TransportStrategy.SMTP_TLS);

        mailer.sendMail(email);

        setEmailLastSentDate(currentUser);
    }
}

From source file:org.flywaydb.core.internal.util.XMysqlToH2SqlReplacerTests.java

/**
 * Read class path file//from  w w w . j av a 2 s . c om
 * 
 * @param path path
 * @param joiner joiner
 * @return string in file
 */
private String readClassPathFile(String path, String joiner) {

    try {

        return Files.lines(Paths.get(new ClassPathResource(path).getURI()), StandardCharsets.UTF_8)
                .collect(Collectors.joining(joiner));
    } catch (IOException e) {

        throw new IllegalStateException("Failed to read class path file", e);
    }
}

From source file:org.elasticsearch.upgrades.WatcherRestartIT.java

private void ensureWatcherStarted() throws Exception {
    assertBusy(() -> {//  w w  w  .j a  v  a2 s  . c  o m
        Response response = client().performRequest(new Request("GET", "_xpack/watcher/stats"));
        String responseBody = EntityUtils.toString(response.getEntity(), StandardCharsets.UTF_8);
        assertThat(responseBody, containsString("\"watcher_state\":\"started\""));
        assertThat(responseBody, not(containsString("\"watcher_state\":\"starting\"")));
        assertThat(responseBody, not(containsString("\"watcher_state\":\"stopping\"")));
        assertThat(responseBody, not(containsString("\"watcher_state\":\"stopped\"")));
    });
}

From source file:com.shenit.commons.utils.ShortLinkUtils.java

/**
 * Shorten url//from   ww w .ja v  a  2  s  .c  om
 * @param url URL that not encoded
 * @param query
 * @return
 */
public static String shorten(String url, String query, Object salt) {
    if (StringUtils.isEmpty(url))
        return null;
    String joinStr = url.indexOf(HttpUtils.QUERY_CHAR) > 0 ? HttpUtils.QUERY_CHAR : HttpUtils.AMP;
    final String queryParams = (query != null) ? joinStr + query : StringUtils.EMPTY;
    String saltStr = DataUtils.toString(salt, StringUtils.EMPTY);
    url = toUrl((url + queryParams));
    return StringUtils.isEmpty(url) ? null
            : Hashing.murmur3_32().hashString(url + HttpUtils.HASH_CHAR + saltStr, StandardCharsets.UTF_8)
                    .toString();
}

From source file:cop.raml.mocks.FileObjectMock.java

@Override
public InputStream openInputStream() throws IOException {
    return data != null ? IOUtils.toInputStream(data, StandardCharsets.UTF_8) : null;
}

From source file:io.apicurio.hub.core.storage.jdbc.DdlParser.java

/**
 * @param ddlStream/*from w  ww.  j av  a 2  s . c o m*/
 * @throws IOException
 */
public List<String> parse(InputStream ddlStream) throws IOException {
    List<String> rval = new LinkedList<>();
    BufferedReader reader = new BufferedReader(new InputStreamReader(ddlStream, StandardCharsets.UTF_8));
    String line;
    StringBuilder builder = new StringBuilder();
    boolean isInMultiLineStatement = false;
    while ((line = reader.readLine()) != null) {
        if (line.startsWith("--")) {
            continue;
        }
        if (line.trim().isEmpty()) {
            continue;
        }
        if (line.endsWith("'") || line.endsWith("(")) {
            isInMultiLineStatement = true;
        }
        if (line.startsWith("'") || line.startsWith(")")) {
            isInMultiLineStatement = false;
        }
        builder.append(line);
        builder.append("\n");

        if (!isInMultiLineStatement) {
            String sqlStatement = builder.toString().trim();
            if (sqlStatement.endsWith(";")) {
                sqlStatement = sqlStatement.substring(0, sqlStatement.length() - 1);
            }
            rval.add(sqlStatement);
            builder = new StringBuilder();
        }
    }
    return rval;
}

From source file:com.evolveum.midpoint.cli.common.ToolsUtils.java

public static void serializeObject(Object object, Writer writer) throws JAXBException {
    if (object == null) {
        return;//from  w w  w .  ja  v a2s.  c om
    }

    Marshaller marshaller = JAXB_CONTEXT.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_ENCODING, StandardCharsets.UTF_8.name());
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);

    if (object instanceof ObjectType) {
        object = new JAXBElement(C_OBJECT, Object.class, object);
    }

    marshaller.marshal(object, writer);
}

From source file:org.zalando.logbook.httpclient.ResponseTest.java

@Test
public void shouldReturnDefaultCharsetIfNoneGiven() {
    assertThat(unit.getCharset(), is(StandardCharsets.UTF_8));
}

From source file:io.syndesis.controllers.extension.ExtensionDataProviderTest.java

@Test
public void shouldGetCorrectDataByExtensionId() throws IOException {
    final DataManager dataManager = mock(DataManager.class);
    final FileStore fileStore = mock(FileStore.class);
    ExtensionDataProvider extensionDataProvider = new ExtensionDataProvider(dataManager, fileStore);

    String sampleBinaryData = "Hello";
    Extension sampleMetadata = new Extension.Builder().id("1234").status(Extension.Status.Installed)
            .extensionId("extensionId").description("Description").build();

    when(fileStore.read("/extensions/1234"))
            .thenReturn(new ByteArrayInputStream(sampleBinaryData.getBytes(StandardCharsets.UTF_8)));
    when(dataManager.fetchIdsByPropertyValue(Extension.class, "extensionId", "extensionId", "status",
            Extension.Status.Installed.name())).thenReturn(Collections.singleton("1234"));
    when(dataManager.fetch(Extension.class, "1234")).thenReturn(sampleMetadata);

    assertThat(extensionDataProvider.getExtensionMetadata("extensionId")).isEqualTo(sampleMetadata);
    assertThat(IOUtils.toString(extensionDataProvider.getExtensionBinaryFile("extensionId"),
            StandardCharsets.UTF_8)).isEqualTo(sampleBinaryData);
}

From source file:de.huxhorn.lilith.swing.AboutDialog.java

public AboutDialog(Frame owner, String title, String appName) {
    super(owner, title, false);
    wasScrolling = true;/*from  w  w w . j  a v a 2 s .  c  om*/
    setLayout(new BorderLayout());
    InputStream is = MainFrame.class.getResourceAsStream("/about/aboutText.txt");
    String aboutText = null;
    final Logger logger = LoggerFactory.getLogger(AboutDialog.class);
    if (is != null) {
        try {
            aboutText = IOUtils.toString(is, StandardCharsets.UTF_8);
        } catch (IOException e) {
            if (logger.isErrorEnabled())
                logger.error("Exception while loading aboutText!! *grrr*");
        }
    }
    try {
        aboutPanel = new AboutPanel(MainFrame.class.getResource("/about/lilith_big.jpg"),
                new Rectangle(50, 50, 400, 200), aboutText, MainFrame.class.getResource("/about/lilith.jpg"),
                appName, 20);
        //aboutPanel.setDebug(true);
        add(aboutPanel, BorderLayout.CENTER);
    } catch (IOException e) {
        if (logger.isErrorEnabled())
            logger.error("Exception creating about panel!!");
    }
    setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        /**
         * Invoked when a window is in the process of being closed.
         * The close operation can be overridden at this point.
         */
        @Override
        public void windowClosing(WindowEvent e) {
            setVisible(false);
        }
    });

}