Example usage for com.google.common.base Charsets UTF_16LE

List of usage examples for com.google.common.base Charsets UTF_16LE

Introduction

In this page you can find the example usage for com.google.common.base Charsets UTF_16LE.

Prototype

Charset UTF_16LE

To view the source code for com.google.common.base Charsets UTF_16LE.

Click Source Link

Document

UTF-16LE: sixteen-bit UCS Transformation Format, little-endian byte order.

Usage

From source file:org.clitherproject.clither.server.net.packet.Packet.java

@SuppressWarnings("deprecation")
public static String readUTF16(ByteBuf in) {
    in = in.order(ByteOrder.BIG_ENDIAN);
    ByteBuf buffer = in.alloc().buffer();
    char chr;/*from  www  .  j  a  v  a2  s. co m*/
    while (in.readableBytes() > 1 && (chr = in.readChar()) != 0) {
        buffer.writeChar(chr);
    }

    return buffer.toString(Charsets.UTF_16LE);
}

From source file:ru.calypso.ogar.server.net.packet.Packet.java

public static String readUTF16(ByteBuf in) {
    in = in.order(ByteOrder.BIG_ENDIAN);
    ByteBuf buffer = in.alloc().buffer();
    char chr;//  www  .  j a v  a 2 s  .  c o m
    while (in.readableBytes() > 1 && (chr = in.readChar()) != 0) {
        buffer.writeChar(chr);
    }

    return buffer.toString(Charsets.UTF_16LE);
}

From source file:org.clitherproject.clither.server.net.packet.Packet.java

@SuppressWarnings("deprecation")
public static void writeUTF16(ByteBuf out, String s) {
    out.order(ByteOrder.BIG_ENDIAN).writeBytes(s.getBytes(Charsets.UTF_16LE));
    out.writeChar(0);/*from w w w. j a  va  2s.  c o m*/
}

From source file:ru.calypso.ogar.server.net.packet.Packet.java

public static void writeUTF16(ByteBuf out, String s) {
    out.order(ByteOrder.BIG_ENDIAN).writeBytes(s.getBytes(Charsets.UTF_16LE));
    out.writeChar(0);
}

From source file:org.obm.push.protocol.data.WCHAREncoder.java

public byte[] toByteArray(String toEncodeString) {
    Preconditions.checkNotNull(toEncodeString);

    return toEncodeString.getBytes(Charsets.UTF_16LE);
}

From source file:org.obm.push.protocol.data.WCHAREncoder.java

public String byteArrayToEncode(byte[] toEncodeByteArray) {
    Preconditions.checkNotNull(toEncodeByteArray);

    return new String(toEncodeByteArray, Charsets.UTF_16LE);
}

From source file:com.android.tools.idea.welcome.config.InstallerData.java

@Nullable
private static Map<String, String> readProperties() {
    try {//www.ja  va  2s  . c  om
        // Firstrun properties file contains a series of "key=value" lines.
        File file = new File(AndroidLocation.getFolder(), PATH_FIRST_RUN_PROPERTIES);
        if (file.isFile()) {
            Map<String, String> properties = Maps.newHashMap();
            final List<String> lines = Files.readLines(file, Charsets.UTF_16LE);
            for (String line : lines) {
                int keyValueSeparator = line.indexOf('=');
                if (keyValueSeparator < 0) {
                    continue;
                }
                final String key = line.substring(0, keyValueSeparator).trim();
                final String value = line.substring(keyValueSeparator + 1).trim();
                if (key.isEmpty()) {
                    continue;
                }
                properties.put(key, value);
            }
            return properties;
        }
    } catch (AndroidLocation.AndroidLocationException | IOException e) {
        LOG.error(e);
    }
    return null;
}

From source file:de.unentscheidbar.validation.swing.GuiTestCase.java

@Before
public final void before() {

    festHelper.setUp();/*from  ww w  .j  a  v a 2s. c  om*/
    robot = new FixedRobot(festHelper.getRobot());
    rnd = new SecureRandom("Rue Truck Jailer Drug".getBytes(Charsets.UTF_16LE));
    robot.settings().delayBetweenEvents(1);
    robot.settings().eventPostingDelay(1);
    runInEdt(new Runnable() {

        @Override
        public void run() {

            gui = new Gui();
            doSetUp();
        }
    });
}

From source file:jenkins.branch.WorkspaceLocatorImpl.java

private static String uniqueSuffix(String name) {
    // TODO still in beta: byte[] sha256 = Hashing.sha256().hashString(name).asBytes();
    byte[] sha256;
    try {//from  w w w .j a  v a 2 s .co  m
        sha256 = MessageDigest.getInstance("SHA-256").digest(name.getBytes(Charsets.UTF_16LE));
    } catch (NoSuchAlgorithmException x) {
        throw new AssertionError(
                "https://docs.oracle.com/javase/7/docs/technotes/guides/security/StandardNames.html#MessageDigest",
                x);
    }
    return new Base32(0).encodeToString(sha256).replaceFirst("=+$", "");
}

From source file:org.polymap.p4.data.imports.refine.csv.CSVFileImporter.java

@Override
public void createPrompts(IProgressMonitor monitor) throws Exception {
    // charset prompt
    site.newPrompt("encoding").summary.put("Zeichensatz der Daten").description.put(
            "Die Daten knnen bspw. deutsche Umlaute enthalten, die nach dem Hochladen falsch dargestellt werden. "
                    + "Mit dem ndern des Zeichensatzes kann dies korrigiert werden.").extendedUI
                            .put(new PromptUIBuilder() {

                                private String encoding;

                                @Override
                                public void submit(ImporterPrompt prompt) {
                                    formatAndOptions().setEncoding(encoding);
                                    updateOptions();
                                    prompt.ok.set(true);
                                    prompt.value.set(encoding);
                                }/*from  www.jav a2 s . c  o m*/

                                @Override
                                public void createContents(ImporterPrompt prompt, Composite parent,
                                        IPanelToolkit tk) {
                                    // select box
                                    Combo combo = new Combo(parent, SWT.SINGLE);
                                    List<String> encodings = Lists.newArrayList(Charsets.ISO_8859_1.name(),
                                            Charsets.US_ASCII.name(), Charsets.UTF_8.name(),
                                            Charsets.UTF_16.name(), Charsets.UTF_16BE.name(),
                                            Charsets.UTF_16LE.name());

                                    // java.nio.charset.Charset.forName( )
                                    combo.setItems(encodings.toArray(new String[encodings.size()]));
                                    // combo.add

                                    combo.addSelectionListener(new SelectionAdapter() {

                                        @Override
                                        public void widgetSelected(SelectionEvent e) {
                                            Combo c = (Combo) e.getSource();
                                            encoding = encodings.get(c.getSelectionIndex());
                                        }
                                    });
                                    encoding = formatAndOptions().encoding();
                                    int index = encodings.indexOf(encoding);
                                    if (index != -1) {
                                        combo.select(index);
                                    }
                                }
                            });

    site.newPrompt("headline").summary.put("Kopfzeile").description
            .put("Welche Zeile enhlt die Spaltenberschriften?").extendedUI.put(new PromptUIBuilder() {

                private int index;

                @Override
                public void createContents(ImporterPrompt prompt, Composite parent, IPanelToolkit tk) {
                    // TODO use a rhei numberfield here
                    Text text = new Text(parent, SWT.RIGHT);
                    text.setText(formatAndOptions().headerLines());
                    text.addModifyListener(event -> {
                        Text t = (Text) event.getSource();
                        // can throw an exception
                        index = Integer.parseInt(t.getText());
                    });
                    // initial value
                    index = Integer.parseInt(text.getText());
                }

                @Override
                public void submit(ImporterPrompt prompt) {
                    formatAndOptions().setHeaderLines(index);
                    updateOptions();
                    prompt.ok.set(true);
                    prompt.value.set(String.valueOf(index));
                }
            });
}