List of usage examples for java.io DataOutputStream writeUTF
public final void writeUTF(String str) throws IOException
From source file:com.fullhousedev.globalchat.bukkit.PluginMessageManager.java
public static void sendSyncResponse(String playerList, String socialSpy, String toggledUsers, String serverName, String requestingServer, Plugin pl) { try {/*from w w w . jav a2 s.c om*/ ByteArrayOutputStream customData = new ByteArrayOutputStream(); DataOutputStream outCustom = new DataOutputStream(customData); outCustom.writeUTF(serverName); outCustom.writeUTF(playerList); sendRawMessage("UserSyncResp", requestingServer, customData.toByteArray(), pl); } catch (IOException ex) { Logger.getLogger(GlobalChat.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.fullhousedev.globalchat.bukkit.PluginMessageManager.java
public static void chatMessage(String userTo, String userFrom, String message, Plugin pl) { try {/*from w ww . j av a 2 s . c om*/ ByteArrayOutputStream customData = new ByteArrayOutputStream(); DataOutputStream outCustom = new DataOutputStream(customData); outCustom.writeUTF(userTo); outCustom.writeUTF(userFrom); outCustom.writeUTF(message); sendRawMessage("chatmessage", "ALL", customData.toByteArray(), pl); } catch (IOException ex) { Logger.getLogger(GlobalChat.class.getName()).log(Level.SEVERE, null, ex); } }
From source file:com.fullhousedev.globalchat.bukkit.PluginMessageManager.java
public static void getServerName(Plugin pl) { ByteArrayOutputStream b = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(b); try {/* w ww. java 2 s . co m*/ out.writeUTF("GetServer"); } catch (IOException ex) { Logger.getLogger(GlobalChat.class.getName()).log(Level.SEVERE, null, ex); } if (Bukkit.getOnlinePlayers().length == 0) { EventListeners.waitingOnJoin = true; return; } Player p = Bukkit.getOnlinePlayers()[0]; p.sendPluginMessage(pl, "BungeeCord", b.toByteArray()); }
From source file:com.fullhousedev.globalchat.bukkit.PluginMessageManager.java
public static void sendRawMessage(String subChannel, String serverName, byte[] message, Plugin pl) { ByteArrayOutputStream b = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(b); try {//from w w w .j a v a 2 s .c o m out.writeUTF("Forward"); out.writeUTF(serverName); out.writeUTF(subChannel); out.writeShort(message.length); out.write(message); } catch (IOException ex) { Logger.getLogger(GlobalChat.class.getName()).log(Level.SEVERE, null, ex); } Player p = Bukkit.getOnlinePlayers()[0]; p.sendPluginMessage(pl, "BungeeCord", b.toByteArray()); }
From source file:org.apache.hive.hcatalog.streaming.mutate.client.AcidTableSerializer.java
/** Returns a base 64 encoded representation of the supplied {@link AcidTable}. */ public static String encode(AcidTable table) throws IOException { DataOutputStream data = null; ByteArrayOutputStream bytes = new ByteArrayOutputStream(); try {// w ww .j ava 2 s . c o m data = new DataOutputStream(bytes); data.writeUTF(table.getDatabaseName()); data.writeUTF(table.getTableName()); data.writeBoolean(table.createPartitions()); if (table.getTransactionId() <= 0) { LOG.warn("Transaction ID <= 0. The recipient is probably expecting a transaction ID."); } data.writeLong(table.getTransactionId()); data.writeByte(table.getTableType().getId()); Table metaTable = table.getTable(); if (metaTable != null) { byte[] thrift = new TSerializer(new TCompactProtocol.Factory()).serialize(metaTable); data.writeInt(thrift.length); data.write(thrift); } else { LOG.warn("Meta store table is null. The recipient is probably expecting an instance."); data.writeInt(0); } } catch (TException e) { throw new IOException("Error serializing meta store table.", e); } finally { data.close(); } return PROLOG_V1 + new String(Base64.encodeBase64(bytes.toByteArray()), Charset.forName("UTF-8")); }
From source file:MethodHashing.java
public static long methodHash(Method method) throws Exception { Class[] parameterTypes = method.getParameterTypes(); String methodDesc = method.getName() + "("; for (int j = 0; j < parameterTypes.length; j++) { methodDesc += getTypeString(parameterTypes[j]); }/*from w ww . java 2 s. co m*/ methodDesc += ")" + getTypeString(method.getReturnType()); long hash = 0; ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(512); MessageDigest messagedigest = MessageDigest.getInstance("SHA"); DataOutputStream dataoutputstream = new DataOutputStream( new DigestOutputStream(bytearrayoutputstream, messagedigest)); dataoutputstream.writeUTF(methodDesc); dataoutputstream.flush(); byte abyte0[] = messagedigest.digest(); for (int j = 0; j < Math.min(8, abyte0.length); j++) hash += (long) (abyte0[j] & 0xff) << j * 8; return hash; }
From source file:MethodHashing.java
public static long constructorHash(Constructor method) throws Exception { Class[] parameterTypes = method.getParameterTypes(); String methodDesc = method.getName() + "("; for (int j = 0; j < parameterTypes.length; j++) { methodDesc += getTypeString(parameterTypes[j]); }/* www .j a va 2 s . com*/ methodDesc += ")"; long hash = 0; ByteArrayOutputStream bytearrayoutputstream = new ByteArrayOutputStream(512); MessageDigest messagedigest = MessageDigest.getInstance("SHA"); DataOutputStream dataoutputstream = new DataOutputStream( new DigestOutputStream(bytearrayoutputstream, messagedigest)); dataoutputstream.writeUTF(methodDesc); dataoutputstream.flush(); byte abyte0[] = messagedigest.digest(); for (int j = 0; j < Math.min(8, abyte0.length); j++) hash += (long) (abyte0[j] & 0xff) << j * 8; return hash; }
From source file:com.reactivetechnologies.jaxrs.RestServerTest.java
static String sendPost(String url, String content) throws IOException { StringBuilder response = new StringBuilder(); HttpURLConnection con = null; BufferedReader in = null;/*w w w .ja v a 2 s .c o m*/ try { URL obj = new URL(url); con = (HttpURLConnection) obj.openConnection(); // optional default is GET con.setRequestMethod("POST"); //add request header con.setRequestProperty("User-Agent", "Mozilla/5.0"); con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); // Send post request con.setDoOutput(true); DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeUTF(content); wr.flush(); wr.close(); int responseCode = con.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { response.append(inputLine); } } else { throw new IOException("Response Code: " + responseCode); } return response.toString(); } catch (IOException e) { throw e; } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } if (con != null) { con.disconnect(); } } }
From source file:com.reactivetechnologies.jaxrs.RestServerTest.java
static String sendDelete(String url, String content) throws IOException { StringBuilder response = new StringBuilder(); HttpURLConnection con = null; BufferedReader in = null;// www .j ava 2 s .co m try { URL obj = new URL(url); con = (HttpURLConnection) obj.openConnection(); // optional default is GET con.setRequestMethod("DELETE"); //add request header con.setRequestProperty("User-Agent", "Mozilla/5.0"); con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); // Send post request con.setDoOutput(true); DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeUTF(content); wr.flush(); wr.close(); int responseCode = con.getResponseCode(); if (responseCode == HttpURLConnection.HTTP_OK) { in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; while ((inputLine = in.readLine()) != null) { response.append(inputLine); } } else { throw new IOException("Response Code: " + responseCode); } return response.toString(); } catch (IOException e) { throw e; } finally { if (in != null) { try { in.close(); } catch (IOException e) { } } if (con != null) { con.disconnect(); } } }
From source file:truco.plugin.utils.Utils.java
public static void TeleportarTPBG(String server, CommandSender sender) { Bukkit.getMessenger().registerOutgoingPluginChannel(CardWarsPlugin._instance, "BungeeCord"); ByteArrayOutputStream b = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(b); try {//w w w . j av a 2s . c o m out.writeUTF("Connect"); out.writeUTF(server); } catch (IOException localIOException) { } ((PluginMessageRecipient) sender).sendPluginMessage(CardWarsPlugin._instance, "BungeeCord", b.toByteArray()); }