List of usage examples for java.io DataOutputStream writeUTF
public final void writeUTF(String str) throws IOException
From source file:ch.unil.genescore.vegas.Snp.java
/** * Write genotype information of this snp to the binary file. Format is: * 0. id_// w w w . j a v a 2 s. com * 1. genotypes_.length * 2. genotypes_[] * 3. maf_ * 4. alleleMean_ * 5. alleleSd_ * @throws IOException */ public void writeGenotype(DataOutputStream os) throws IOException { // NOTE: CHANGE ALSO readBinary() AND skip() WHEN CHANGING ANYTHING HERE! os.writeUTF(id_); for (int i = 0; i < genotypes_.length; i++) os.writeByte(genotypes_[i]); os.writeDouble(maf_); os.writeDouble(alleleMean_); os.writeDouble(alleleSd_); }
From source file:PersistentRankingMIDlet.java
private byte[] toByteArray(BookInfo bookInfo) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream os = new DataOutputStream(baos); os.writeUTF(bookInfo.isbn); os.writeUTF(bookInfo.title == null ? "" : bookInfo.title); os.writeInt(bookInfo.ranking);/*from w w w .j a va 2s.c o m*/ os.writeInt(bookInfo.reviews); os.writeInt(bookInfo.lastRanking); os.writeInt(bookInfo.lastReviews); return baos.toByteArray(); }
From source file:com.trigger_context.Main_Service.java
private void takeAction(String mac, InetAddress ip) { noti("comes to ", mac); SharedPreferences conditions = getSharedPreferences(mac, MODE_PRIVATE); Map<String, ?> cond_map = conditions.getAll(); Set<String> key_set = cond_map.keySet(); Main_Service.main_Service.noti(cond_map.toString(), ""); if (key_set.contains("SmsAction")) { String number = conditions.getString("SmsActionNumber", null); String message = conditions.getString("SmsActionMessage", null); try {//from w w w . ja va 2s . co m SmsManager smsManager = SmsManager.getDefault(); smsManager.sendTextMessage(number, null, message, null, null); noti("Sms Sent To : ", "" + number); } catch (Exception e) { noti("Sms Sending To ", number + "Failed"); } } if (key_set.contains("OpenWebsiteAction")) { Intent dialogIntent = new Intent(getBaseContext(), Action_Open_Url.class); dialogIntent.putExtra("urlAction", (String) cond_map.get("urlAction")); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); } if (key_set.contains("ToggleAction")) { if (key_set.contains("bluetoothAction") && conditions.getBoolean("bluetoothAction", false)) { final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothAdapter.enable(); } else if (key_set.contains("bluetoothAction")) { final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); bluetoothAdapter.disable(); } if (key_set.contains("wifiAction") && conditions.getBoolean("wifiAction", false)) { final WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); wm.setWifiEnabled(true); } else if (key_set.contains("wifiAction")) { final WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE); wm.setWifiEnabled(false); } } if (key_set.contains("TweetAction")) { Intent dialogIntent = new Intent(getBaseContext(), Action_Post_Tweet.class); dialogIntent.putExtra("tweetTextAction", (String) cond_map.get("tweetTextAction")); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); } if (key_set.contains("EmailAction")) { Intent dialogIntent = new Intent(getBaseContext(), Action_Email_Client.class); dialogIntent.putExtra("toAction", (String) cond_map.get("toAction")); dialogIntent.putExtra("subjectAction", (String) cond_map.get("subjectAction")); dialogIntent.putExtra("emailMessageAction", (String) cond_map.get("emailMessageAction")); dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); getApplication().startActivity(dialogIntent); } if (key_set.contains("RemoteServerCmd")) { String text = conditions.getString("cmd", null); new Thread(new SendData("224.0.0.1", 9876, text)).start(); } // network activities from here. // in all network actions send username first if (key_set.contains("FileTransferAction")) { String path = conditions.getString("filePath", null); SharedPreferences my_data = getSharedPreferences(Main_Service.MY_DATA, MODE_PRIVATE); String usrName = my_data.getString("name", "userName"); // type 1 try { Socket socket = new Socket(ip, COMM_PORT); DataOutputStream out = null; out = new DataOutputStream(socket.getOutputStream()); out.writeUTF(usrName); out.writeInt(1); sendFile(out, path); noti("Sent " + path + " file to :", getSharedPreferences(Main_Service.USERS, MODE_PRIVATE).getString("name", "userName")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (key_set.contains("ccfMsgAction")) { String msg = conditions.getString("ccfMsg", null); SharedPreferences my_data = getSharedPreferences(Main_Service.MY_DATA, MODE_PRIVATE); String usrName = my_data.getString("name", "userName"); // type 2 is msg try { Socket socket = new Socket(ip, COMM_PORT); DataOutputStream out = null; out = new DataOutputStream(socket.getOutputStream()); out.writeUTF(usrName); out.writeInt(2); out.writeUTF(msg); noti("Sent msg : '" + msg + "'", "to : " + getSharedPreferences(Main_Service.USERS, MODE_PRIVATE).getString("name", "userName")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } if (key_set.contains("sync")) { SharedPreferences my_data = getSharedPreferences(Main_Service.MY_DATA, MODE_PRIVATE); String usrName = my_data.getString("name", "userName"); // type 3 is sync try { Socket socket = new Socket(ip, COMM_PORT); DataInputStream in = new DataInputStream(socket.getInputStream()); DataOutputStream out = new DataOutputStream(socket.getOutputStream()); out.writeUTF(usrName); out.writeInt(3); senderSync(in, out, Environment.getExternalStorageDirectory().getPath() + "/TriggerSync/"); noti("Synced with:", getSharedPreferences(Main_Service.USERS, MODE_PRIVATE).getString("name", "userName")); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
From source file:org.prorefactor.refactor.PUB.java
private void writeHeader(DataOutputStream out, SymbolScopeRoot unitScope) throws IOException { String s = unitScope.getClassName(); if (s != null) out.writeUTF(s); else// w w w . j a v a 2 s .c o m out.writeUTF(""); SymbolScopeSuper superScope = (SymbolScopeSuper) unitScope.getParentScope(); if (superScope != null) out.writeUTF(superScope.getClassName()); else out.writeUTF(""); }
From source file:org.prorefactor.refactor.PUB.java
private void writeStrings(DataOutputStream out) throws IOException { int size = stringTable.size(); out.writeInt(size);/* w ww. ja v a 2 s . co m*/ for (int i = 0; i < size; i++) { out.writeUTF((String) stringTable.get(new Integer(i))); } }
From source file:SafeUTF.java
public void safeWriteUTF(DataOutputStream out, String str) throws IOException { if (str == null) { out.writeByte(NULL);//from w w w. j a v a2s .c om } else { int len = str.length(); short numChunks; if (len == 0) { numChunks = 0; } else { numChunks = (short) (((len - 1) / chunkSize) + 1); } out.writeByte(NOT_NULL); out.writeShort(numChunks); int i = 0; while (len > 0) { int beginCopy = i * chunkSize; int endCopy = len <= chunkSize ? beginCopy + len : beginCopy + chunkSize; String theChunk = str.substring(beginCopy, endCopy); out.writeUTF(theChunk); len -= chunkSize; i++; } } }
From source file:org.prorefactor.refactor.PUB.java
private void writeFileIndex(DataOutputStream out) throws IOException { String[] files = tree.getFilenames(); for (int i = 0; i < files.length; i++) { out.writeInt(i);/* ww w .j ava2s .com*/ out.writeUTF(files[i]); } out.writeInt(-1); out.writeUTF(""); }
From source file:cn.ac.ncic.mastiff.io.coding.DeltaBinaryPackingStringReader.java
@Override public byte[] ensureDecompressed() throws IOException { System.out.println("280 inBuf.length " + inBuf.getLength()); FlexibleEncoding.Parquet.DeltaByteArrayReader reader = new FlexibleEncoding.Parquet.DeltaByteArrayReader(); DataOutputBuffer transfer = new DataOutputBuffer(); transfer.write(inBuf.getData(), 12, inBuf.getLength() - 12); byte[] data = transfer.getData(); System.out.println("286 byte [] data " + data.length + " numPairs " + numPairs); inBuf.close();//from w ww .j a v a2 s . c o m Binary[] bin = new Utils().readData(reader, data, numPairs); System.out.println("2998 Binary[] bin " + bin.length); ByteArrayOutputStream bos1 = new ByteArrayOutputStream(); DataOutputStream dos1 = new DataOutputStream(bos1); ByteArrayOutputStream bos2 = new ByteArrayOutputStream(); DataOutputStream dos2 = new DataOutputStream(bos2); // DataOutputBuffer decoding = new DataOutputBuffer(); // DataOutputBuffer offset = new DataOutputBuffer(); dos1.writeInt(decompressedSize); dos1.writeInt(numPairs); dos1.writeInt(startPos); int dataoffset = 12; String str; for (int i = 0; i < numPairs; i++) { str = bin[i].toStringUsingUTF8(); dos1.writeUTF(str); dataoffset = dos1.size(); dos2.writeInt(dataoffset); } System.out.println("315 offset.size() " + bos2.size() + " decoding.szie " + bos2.toByteArray().length); System.out.println("316 dataoffet " + dataoffset); dos1.write(bos2.toByteArray(), 0, bos2.size()); inBuf.close(); System.out.println("316 bos1 " + bos1.toByteArray().length + " " + bos1.size()); byte[] bytes = bos1.toByteArray(); dos2.close(); bos2.close(); bos1.close(); dos1.close(); return bytes; }
From source file:org.apache.jackrabbit.core.persistence.mem.InMemBundlePersistenceManager.java
/** * Writes the content of the hash maps stores to the file system. * * @throws Exception if an error occurs/*from ww w .j a v a 2s. co m*/ */ public synchronized void storeContents() throws Exception { // write bundles FileSystemResource fsRes = new FileSystemResource(wspFS, BUNDLE_FILE_PATH); fsRes.makeParentDirs(); BufferedOutputStream bos = new BufferedOutputStream(fsRes.getOutputStream()); DataOutputStream out = new DataOutputStream(bos); try { out.writeInt(bundleStore.size()); // number of entries // entries for (NodeId id : bundleStore.keySet()) { out.writeUTF(id.toString()); // id byte[] data = bundleStore.get(id); out.writeInt(data.length); // data length out.write(data); // data } } finally { out.close(); } // write references fsRes = new FileSystemResource(wspFS, REFS_FILE_PATH); fsRes.makeParentDirs(); bos = new BufferedOutputStream(fsRes.getOutputStream()); out = new DataOutputStream(bos); try { out.writeInt(refsStore.size()); // number of entries // entries for (NodeId id : refsStore.keySet()) { out.writeUTF(id.toString()); // target id byte[] data = refsStore.get(id); out.writeInt(data.length); // data length out.write(data); // data } } finally { out.close(); } if (!useFileBlobStore) { // write blobs fsRes = new FileSystemResource(wspFS, BLOBS_FILE_PATH); fsRes.makeParentDirs(); bos = new BufferedOutputStream(fsRes.getOutputStream()); out = new DataOutputStream(bos); try { out.writeInt(blobs.size()); // number of entries // entries for (String id : blobs.keySet()) { out.writeUTF(id); // id byte[] data = blobs.get(id); out.writeInt(data.length); // data length out.write(data); // data } } finally { out.close(); } } }
From source file:br.com.anteros.android.synchronism.communication.HttpConnectionClient.java
public MobileResponse sendReceiveData(MobileRequest mobileRequest) { sessionId = HttpConnectionSession.getInstance().getSessionId(); add(mobileRequest.getFormattedHeader(), mobileRequest.getFormatedActions()); MobileResponse mobileResponse = new MobileResponse(); try {/*from ww w . j a va2 s . c o m*/ if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onWaitServer(); } if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onStatusConnectionServer("Conectando Servidor..."); } /* * Define url e estabelece conexo */ HttpPost httpPost = new HttpPost(url); HttpParams httpParameters = new BasicHttpParams(); // Set the timeout in milliseconds until a connection is // established. // The default value is zero, that means the timeout is not used. HttpConnectionParams.setConnectionTimeout(httpParameters, TIMEOUT_CONNECTION); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. HttpConnectionParams.setSoTimeout(httpParameters, TIMEOUT_SOCKET); if (httpClient == null) httpClient = new DefaultHttpClient(httpParameters); // /* * Setar o cookie da sesso */ if ((sessionId != null) && (!"".equals(sessionId))) { httpPost.setHeader("Cookie", "JSESSIONID=" + sessionId); } httpPost.setHeader("User-Agent", "Android"); httpPost.setHeader("Accept-Encoding", "gzip"); if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onStatusConnectionServer("Enviando requisio..."); } // ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(baos); // /* * Escrever no output */ out.writeInt(numOption); String aux[]; for (int i = 0; i < opPOST.size(); i++) { aux = (String[]) opPOST.get(i); out.writeUTF(aux[0]); byte[] b = aux[1].getBytes(); out.writeInt(b.length); out.write(b); aux = null; } out.flush(); ByteArrayEntity entity = new ByteArrayEntity(baos.toByteArray()); entity.setContentEncoding("UTF-8"); httpPost.setEntity(entity); httpPost.addHeader("Connection", "Keep-Alive"); httpPost.addHeader("Keep-Alive", "timeout=120000"); out.close(); // if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onStatusConnectionServer("Recebendo dados..."); } if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onDebugMessage("Recebendo dados conexo"); } /* * Aguardar resposta */ HttpResponse httpResponse = httpClient.execute(httpPost); List result = null; StatusLine statusLine = httpResponse.getStatusLine(); int code = statusLine.getStatusCode(); if (code != 200) { String msg = "Erro RECEBENDO resposta do Servidor " + url + " - Cdigo do Erro HTTP " + code + "-" + statusLine.getReasonPhrase(); mobileResponse.setStatus(msg); } else { if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onStatusConnectionServer("Resposta OK !"); } /* * Ler cookie */ String tmpSessionId = null; for (Cookie c : httpClient.getCookieStore().getCookies()) { if ("JSESSIONID".equals(c.getName())) { tmpSessionId = c.getValue(); } } if (tmpSessionId != null) { sessionId = tmpSessionId; HttpConnectionSession.getInstance().setSessionId(sessionId); } // if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onStatusConnectionServer("Lendo dados..."); } /* * Le os dados */ HttpEntity entityResponse = httpResponse.getEntity(); InputStream in = AndroidHttpClient.getUngzippedContent(entityResponse); BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF-8")); String content = null; content = reader.readLine(); String line = null; while ((line = reader.readLine()) != null) { content += line; } line = ""; reader.close(); reader = null; in.close(); in = null; entityResponse.consumeContent(); entityResponse = null; // StringTokenizer messagePart = new StringTokenizer(content, "#"); content = null; if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onDebugMessage("RECEBEU dados conexo"); } if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onStatusConnectionServer("Processando resposta... "); } if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onDebugMessage("Converteu string dados conexo"); } while (messagePart.hasMoreTokens()) { String resultData = messagePart.nextToken(); resultData = resultData.substring(resultData.indexOf("*") + 1, resultData.length()); if (result == null) result = formatData(resultData); else result.addAll(formatData(resultData)); } messagePart = null; } if (result != null) { mobileResponse.setFormattedParameters(result); result.clear(); result = null; } if (this.getSendData() != null) { for (MobileSendDataListener listener : this.getSendData().getListeners()) listener.onEndServer(); } } catch (SocketTimeoutException exTimeout) { exTimeout.printStackTrace(); wrapException(mobileResponse, "No foi possvel CONECTAR ao Servidor " + url + ". Verifique sua conexo e se o servidor est em funcionamento."); } catch (Exception e) { e.printStackTrace(); if ((e.getMessage() + "").contains("unreachable")) wrapException(mobileResponse, "Voc est sem acesso a internet. Verifique sua conexo. No foi possvel conectar ao servidor " + url); else wrapException(mobileResponse, "No foi possivel CONECTAR ao Servidor " + url + " " + e.getMessage()); } return mobileResponse; }