List of usage examples for com.google.common.base Charsets UTF_16
Charset UTF_16
To view the source code for com.google.common.base Charsets UTF_16.
Click Source Link
From source file:com.facebook.buck.cxx.ByteBufferReplacer.java
private static byte[] getBytes(String str, Charset charset) { byte[] bytes = str.getBytes(charset); // Strip off the byte-order-markers for UTF-16. if (charset == Charsets.UTF_16) { bytes = Arrays.copyOfRange(bytes, 2, bytes.length); }//from w ww. jav a 2s . c o m return bytes; }
From source file:org.jclouds.azurecompute.binders.StorageServiceParamsToXML.java
@Override public <R extends HttpRequest> R bindToRequest(R request, Object input) { StorageServiceParams params = StorageServiceParams.class.cast(input); try {/* ww w . j a v a 2 s . c om*/ XMLBuilder builder = XMLBuilder .create("CreateStorageServiceInput", "http://schemas.microsoft.com/windowsazure") .e("ServiceName").t(params.name()).up() //.e("Description").up() .e("Label").t(BaseEncoding.base64().encode(params.label().getBytes(Charsets.UTF_16))).up() .e("Location").t(params.location()).up() //.e("GeoReplicationEnabled").up() //.e("ExtendedProperties").up() //.e("SecondaryReadEnabled").up() .e("AccountType").t(params.accountType().name()).up(); return (R) request.toBuilder().payload(builder.asString()).build(); } catch (Exception e) { throw propagate(e); } }
From source file:de.ks.flatadocdb.defaults.DefaultIdGenerator.java
public String getSha1Hash(Path repository, Path targetPath) {//for debugging and readability the string is used instead of the byte array. Also avoids possible programming errors using the byte array in equals/hashcode. String relative = getRelativePath(repository, targetPath); MessageDigest digest = sha1.get(); byte[] checksum = digest.digest(relative.getBytes(Charsets.UTF_16)); String hexString = Hex.encodeHexString(checksum); log.trace("Generated {} \"{}\" for {}", digest.getAlgorithm(), hexString, relative); return hexString; }
From source file:org.beaconmc.network.socket.pipeline.PacketLegacy.java
@Override protected void messageReceived(ChannelHandlerContext channelHandlerContext, ByteBuf byteBuf) throws Exception { byteBuf.markReaderIndex();//from w ww .jav a 2s . c o m boolean repliedPing = true; try { short packetId = byteBuf.readUnsignedByte(); if (packetId == 254) { int length = byteBuf.readableBytes(); AsyncServerPingEvent asyncServerPingEvent = EventFactory .callAsyncServerPingEvent(this.server.createServerPing()); if (asyncServerPingEvent.getPing() != null) { switch (length) { case 0: this.sendPingAndClose(channelHandlerContext, this.toArray(String.format("%s%d%d", asyncServerPingEvent.getPing().getDescription().getText(), asyncServerPingEvent.getPing().getPlayers().getOnline(), asyncServerPingEvent.getPing().getPlayers().getMax()))); break; case 1: if (byteBuf.readUnsignedByte() != 1) { return; } this.sendPingAndClose(channelHandlerContext, this.toArray(String.format("1\0%d\0%s\0%s\0%d\0%d", 127, asyncServerPingEvent.getPing().getVersion().getName(), asyncServerPingEvent.getPing().getDescription().getText(), asyncServerPingEvent.getPing().getPlayers().getOnline(), asyncServerPingEvent.getPing().getPlayers().getMax()))); break; default: boolean checkFlag = byteBuf.readUnsignedByte() == 1; checkFlag &= byteBuf.readUnsignedByte() == 250; checkFlag &= "MC|PingHost".equals( new String(byteBuf.readBytes(byteBuf.readShort() * 2).array(), Charsets.UTF_16)); int checkShort = byteBuf.readShort(); checkFlag &= byteBuf.readUnsignedByte() >= 73; checkFlag &= 3 + byteBuf.readBytes(byteBuf.readShort() * 2).array().length + 4 == checkShort; checkFlag &= byteBuf.readInt() <= '\uffff'; checkFlag &= byteBuf.readableBytes() == 0; if (!checkFlag) { return; } this.sendPingAndClose(channelHandlerContext, this.toArray(String.format("1\0%d\0%s\0%s\0%d\0%d", 127, asyncServerPingEvent.getPing().getVersion().getName(), asyncServerPingEvent.getPing().getDescription().getText(), asyncServerPingEvent.getPing().getPlayers().getOnline(), asyncServerPingEvent.getPing().getPlayers().getMax()))); break; } } else { this.close(channelHandlerContext); } repliedPing = false; } else if (packetId == 0x02 && byteBuf.isReadable()) { this.sendPingAndClose(channelHandlerContext, this.toArray(ChatColor.RED + "Outdated Client")); repliedPing = false; } } catch (Exception e) { return; } finally { if (repliedPing) { byteBuf.resetReaderIndex(); channelHandlerContext.channel().pipeline().remove("legacy_ping"); channelHandlerContext.fireChannelRead(byteBuf.retain()); } } }
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 ww w .j a va2s . com @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)); } }); }
From source file:io.warp10.continuum.MetadataUtils.java
public static byte[] idBytes(String id) { return id.getBytes(Charsets.UTF_16); }
From source file:com.cloudera.cdk.morphline.shaded.org.apache.commons.codec.binary.binary.StringUtils.java
/** * Encodes the given string into a sequence of bytes using the UTF-16 charset, storing the result into a new byte * array./* www.j a va 2 s .c o m*/ * * @param string * the String to encode, may be {@code null} * @return encoded bytes, or {@code null} if the input string was {@code null} * @throws NullPointerException * Thrown if {@link Charsets#UTF_16} is not initialized, which should never happen since it is * required by the Java platform specification. * @since As of 1.7, throws {@link NullPointerException} instead of UnsupportedEncodingException * @see <a href="http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a> * @see #getBytesUnchecked(String, String) */ public static byte[] getBytesUtf16(final String string) { return getBytes(string, Charsets.UTF_16); }
From source file:io.selendroid.testapp.webdrivertestserver.WebbitAppServer.java
private WebServer configureServer(int port) { WebServer server = WebServers.createWebServer(newFixedThreadPool(5), port); // Note: Does first matching prefix matching, so /common/foo must be set up before /common // Delegating to a PathMatchHandler can be used to limit this forwardPathToHandlerUnderCommon("/page", new LastPathSegmentHandler(), server); forwardPathToHandlerUnderCommon("/redirect", new RedirectHandler("resultPage.html"), server); forwardPathToHandlerUnderCommon("/sleep", new SleepHandler(), server); forwardPathToHandlerUnderCommon("/encoding", new StringHttpHandler("text/html", SHALOM_TEXT, Charsets.UTF_16), server); forwardPathToHandlerUnderCommon("/upload", new PathMatchHandler("^$", new UploadFileHandler()), server); forwardPathToHandlerUnderCommon("/basicAuth", new BasicAuthHandler("test:test"), server); forwardPathToHandlerUnderCommon("/quitquitquit", new QuitQuitQuitHandler(), server); server.add(new PathAugmentingStaticFileHandler( InProject.locate("file:///data/data/io.selendroid.testapp/web"), "/common")); server.add(new PathAugmentingStaticFileHandler(InProject.locate("file:///android_asset/javascript/"), JS_SRC_CONTEXT_PATH));/*w w w . ja v a2s.c o m*/ server.add(new PathAugmentingStaticFileHandler(InProject.locate("/third_party/closure/goog"), CLOSURE_CONTEXT_PATH)); server.add(new PathAugmentingStaticFileHandler(InProject.locate("/third_party/js"), THIRD_PARTY_JS_CONTEXT_PATH)); return server; }
From source file:org.openqa.selendroid.testapp.webdrivertestserver.WebbitAppServer.java
private WebServer configureServer(int port) { WebServer server = WebServers.createWebServer(newFixedThreadPool(5), port); // Note: Does first matching prefix matching, so /common/foo must be set up before /common // Delegating to a PathMatchHandler can be used to limit this forwardPathToHandlerUnderCommon("/page", new LastPathSegmentHandler(), server); forwardPathToHandlerUnderCommon("/redirect", new RedirectHandler("resultPage.html"), server); forwardPathToHandlerUnderCommon("/sleep", new SleepHandler(), server); forwardPathToHandlerUnderCommon("/encoding", new StringHttpHandler("text/html", SHALOM_TEXT, Charsets.UTF_16), server); forwardPathToHandlerUnderCommon("/upload", new PathMatchHandler("^$", new UploadFileHandler()), server); forwardPathToHandlerUnderCommon("/basicAuth", new BasicAuthHandler("test:test"), server); forwardPathToHandlerUnderCommon("/quitquitquit", new QuitQuitQuitHandler(), server); server.add(new PathAugmentingStaticFileHandler( InProject.locate("file:///data/data/org.openqa.selendroid.testapp/web"), "/common")); server.add(new PathAugmentingStaticFileHandler(InProject.locate("file:///android_asset/javascript/"), JS_SRC_CONTEXT_PATH));/*from ww w . j a va2 s . co m*/ server.add(new PathAugmentingStaticFileHandler(InProject.locate("/third_party/closure/goog"), CLOSURE_CONTEXT_PATH)); server.add(new PathAugmentingStaticFileHandler(InProject.locate("/third_party/js"), THIRD_PARTY_JS_CONTEXT_PATH)); return server; }
From source file:org.openqa.selenium.environment.webserver.WebbitAppServer.java
private WebServer configureServer(int port) { WebServer server = WebServers.createWebServer(newFixedThreadPool(5), port); // Note: Does first matching prefix matching, so /common/foo must be set up before /common // Delegating to a PathMatchHandler can be used to limit this forwardPathToHandlerUnderCommon("/page", new LastPathSegmentHandler(), server); forwardPathToHandlerUnderCommon("/redirect", new RedirectHandler("resultPage.html"), server); forwardPathToHandlerUnderCommon("/sleep", new SleepHandler(), server); forwardPathToHandlerUnderCommon("/encoding", new StringHttpHandler("text/html", SHALOM_TEXT, Charsets.UTF_16), server); forwardPathToHandlerUnderCommon("/upload", new PathMatchHandler("^$", new UploadFileHandler()), server); forwardPathToHandlerUnderCommon("/basicAuth", new BasicAuthHandler("test:test"), server); forwardPathToHandlerUnderCommon("/quitquitquit", new QuitQuitQuitHandler(), server); server.add(new PathAugmentingStaticFileHandler(InProject.locate("common/src/web"), "/common")); server.add(new PathAugmentingStaticFileHandler(InProject.locate("javascript"), JS_SRC_CONTEXT_PATH)); server.add(new PathAugmentingStaticFileHandler(InProject.locate("/third_party/closure/goog"), CLOSURE_CONTEXT_PATH));//from w w w. j a v a 2s . c o m server.add(new PathAugmentingStaticFileHandler(InProject.locate("/third_party/js"), THIRD_PARTY_JS_CONTEXT_PATH)); return server; }