List of usage examples for java.io DataOutputStream DataOutputStream
public DataOutputStream(OutputStream out)
From source file:net.frontlinesms.DesktopLauncher.java
/** * Generate the User ID this user is going to keep for all its statistics * @return The generated ID as a String//from w ww. jav a2s.c o m */ private static String generateUserId() { Long currentTime = new Long(System.currentTimeMillis()); byte[] bytes; try { ByteArrayOutputStream baos = new ByteArrayOutputStream(); new DataOutputStream(baos).writeLong(currentTime); bytes = baos.toByteArray(); } catch (IOException e) { /* not gonna happen */ throw new IllegalStateException(e); } return Base64Utils.encode(bytes).replace('=', ' ').trim(); }
From source file:com.datatorrent.stram.FSRecoveryHandler.java
@Override public DataOutputStream rotateLog() throws IOException { if (fs.exists(logBackupPath)) { // log backup is purged on snapshot/restore throw new AssertionError("Snapshot state prior to log rotation: " + logBackupPath); }/*from ww w . j a va 2 s.c o m*/ if (fs.exists(logPath)) { LOG.debug("Creating log backup {}", logBackupPath); if (!fs.rename(logPath, logBackupPath)) { throw new IOException("Failed to rotate log: " + logPath); } } LOG.info("Creating {}", logPath); final FSDataOutputStream fsOutputStream; String scheme = null; try { scheme = fs.getScheme(); } catch (UnsupportedOperationException e) { LOG.warn("{} doesn't implement getScheme() method", fs.getClass().getName()); } if ("file".equals(scheme)) { // local FS does not support hflush and does not flush native stream FSUtil.mkdirs(fs, logPath.getParent()); fsOutputStream = new FSDataOutputStream( new FileOutputStream(Path.getPathWithoutSchemeAndAuthority(logPath).toString()), null); } else { fsOutputStream = fs.create(logPath); } DataOutputStream osWrapper = new DataOutputStream(fsOutputStream) { @Override public void flush() throws IOException { super.flush(); fsOutputStream.hflush(); } @Override public void close() throws IOException { LOG.debug("Closing {}", logPath); super.close(); } }; return osWrapper; }
From source file:httpRequests.GetPost.java
private void sendPost() throws Exception { String url = "https://selfsolve.apple.com/wcResults.do"; URL obj = new URL(url); HttpsURLConnection con = (HttpsURLConnection) obj.openConnection(); //add reuqest header con.setRequestMethod("POST"); con.setRequestProperty("User-Agent", USER_AGENT); con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); String urlParameters = "sn=C02G8416DRJM&cn=&locale=&caller=&num=12345"; // Send post request con.setDoOutput(true);/*from www . ja v a 2 s . c o m*/ DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(urlParameters); wr.flush(); wr.close(); int responseCode = con.getResponseCode(); System.out.println("\nSending 'POST' request to URL : " + url); System.out.println("Post parameters : " + urlParameters); System.out.println("Response Code : " + responseCode); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); //print result System.out.println(response.toString()); }
From source file:net.mybox.mybox.ClientStatus.java
private synchronized boolean updateLastSync() { lastSync = (new Date()).getTime(); try {//w w w. j a va 2 s .c om FileOutputStream fos = new FileOutputStream(lastSyncFile); DataOutputStream dos = new DataOutputStream(fos); dos.writeLong(lastSync); dos.close(); } catch (Exception e) { return false; } return true; }
From source file:mendhak.teamcity.stash.api.StashClient.java
private String PostBuildStatusToStash(String targetURL, String body, String authHeader) { HttpURLConnection connection = null; try {//from w w w . j a va 2s .com Logger.LogInfo("Sending build status to " + targetURL); Logger.LogInfo("With body: " + body); Logger.LogInfo("Auth header: " + authHeader); connection = GetConnection(targetURL); connection.setRequestMethod("POST"); connection.setRequestProperty("Content-Type", "application/json"); connection.setRequestProperty("Content-Length", String.valueOf(body.getBytes().length)); connection.setRequestProperty("Authorization", "Basic " + authHeader); connection.setUseCaches(false); connection.setDoInput(true); connection.setDoOutput(true); DataOutputStream wr = new DataOutputStream(connection.getOutputStream()); wr.writeBytes(body); wr.flush(); wr.close(); InputStream is = connection.getInputStream(); BufferedReader rd = new BufferedReader(new InputStreamReader(is)); String line; StringBuilder response = new StringBuilder(); while ((line = rd.readLine()) != null) { response.append(line); response.append("\r\n"); } rd.close(); return response.toString(); } catch (Exception e) { Logger.LogError("Could not send data to Stash. ", e); } finally { if (connection != null) { connection.disconnect(); } } return null; }
From source file:jeeves.utils.EMail.java
/** Sends the message to the mail server *///from w ww.j av a2 s .c o m public boolean send() throws IOException { Socket socket = new Socket(sMailServer, iPort); try { in = new BufferedReader(new InputStreamReader(new DataInputStream(socket.getInputStream()), Charset.forName(Jeeves.ENCODING))); out = new OutputStreamWriter(new DataOutputStream(socket.getOutputStream()), "ISO-8859-1"); if (lookMailServer()) if (sendData("2", "HELO " + InetAddress.getLocalHost().getHostName() + "\r\n")) if (sendData("2", "MAIL FROM: <" + sFrom + ">\r\n")) if (sendData("2", "RCPT TO: <" + sTo + ">\r\n")) if (sendData("354", "DATA\r\n")) if (sendData("2", buildContent())) if (sendData("2", "QUIT\r\n")) return true; sendData("2", "QUIT\r\n"); } finally { IOUtils.closeQuietly(socket); } return false; }
From source file:RemoteDeviceDiscovery.java
public static void postDevice(RemoteDevice d) throws Exception { String url = "http://bluetoothdatabase.com/datacollection/"; URL obj = new URL(url); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); //add reuqest header con.setRequestMethod("POST"); con.setRequestProperty("User-Agent", "blucat"); con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); String urlParameters = deviceJson(d); // Send post request con.setDoOutput(true);/*from w ww . j av a 2 s .c o m*/ DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(urlParameters); wr.flush(); wr.close(); int responseCode = con.getResponseCode(); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); }
From source file:com.dao.ShopThread.java
private boolean doPTShop() throws Exception { long startTime = System.currentTimeMillis(); // loadCookie(); boolean result = true; LogUtil.webPrintf("??..."); String postParams = addPTDynamicParams(); LogUtil.webPrintf("???"); LogUtil.webPrintf("?..."); HttpURLConnection loginConn = getHttpPostConn(this.ptshopurl); loginConn.setRequestProperty("Host", "danbao.5173.com"); loginConn.setRequestProperty("Content-Length", Integer.toString(postParams.length())); LogUtil.debugPrintf("?HEADER===" + loginConn.getRequestProperties()); DataOutputStream wr = new DataOutputStream(loginConn.getOutputStream()); wr.writeBytes(postParams);//from w ww .ja v a 2 s.c o m wr.flush(); wr.close(); int responseCode = loginConn.getResponseCode(); LogUtil.debugPrintf("\nSending 'POST' request to URL : " + this.ptshopurl); LogUtil.debugPrintf("Post parameters : " + postParams); LogUtil.debugPrintf("Response Code : " + responseCode); Map<String, List<String>> header = loginConn.getHeaderFields(); LogUtil.debugPrintf("??HEADER===" + header); List<String> cookie = header.get("Set-Cookie"); if (cookie == null || cookie.size() == 0) { result = false; LogUtil.webPrintf("?!"); } else { LogUtil.webPrintf("??!"); LogUtil.debugPrintf("cookie====" + cookie); LogUtil.debugPrintf("Location :" + loginConn.getURL().toString()); setCookies(cookie); LogUtil.webPrintf("?..."); String payurl = getPayKey(loginConn, "db"); LogUtil.webPrintf("??"); if (payurl != null && !payurl.equals("")) { LogUtil.debugPrintf("?url:" + payurl); LogUtil.webPrintf("..."); pay(payurl); LogUtil.webPrintf("?"); } else { LogUtil.webPrintf("?"); LogUtil.debugPrintf("?url"); } } return result; }
From source file:be.ibridge.kettle.trans.step.sortrows.SortRows.java
private boolean addBuffer(Row r) { if (r != null) { data.buffer.add(r); // Save row }// ww w. jav a 2 s .c o m if (data.files.size() == 0 && r == null) // No more records: sort buffer { quickSort(data.buffer); } // time to write to disk: buffer is full! if (data.buffer.size() == meta.getSortSize() // Buffer is full: sort & dump to disk || (data.files.size() > 0 && r == null && data.buffer.size() > 0) // No more records: join from disk ) { // First sort the rows in buffer[] quickSort(data.buffer); // Then write them to disk... DataOutputStream dos; GZIPOutputStream gzos; int p; try { FileObject fileObject = KettleVFS.createTempFile(meta.getPrefix(), ".tmp", StringUtil.environmentSubstitute(meta.getDirectory())); data.files.add(fileObject); // Remember the files! OutputStream outputStream = fileObject.getContent().getOutputStream(); if (meta.getCompress()) { gzos = new GZIPOutputStream(new BufferedOutputStream(outputStream)); dos = new DataOutputStream(gzos); } else { dos = new DataOutputStream(outputStream); gzos = null; } // How many records do we have? dos.writeInt(data.buffer.size()); for (p = 0; p < data.buffer.size(); p++) { if (p == 0) { // Save the metadata, keep it in memory data.rowMeta.add(new Row(((Row) data.buffer.get(p)))); } // Just write the data, nothing else ((Row) data.buffer.get(p)).writeData(dos); } // Close temp-file dos.close(); // close data stream if (gzos != null) { gzos.close(); // close gzip stream } outputStream.close(); // close file stream } catch (Exception e) { logError("Error processing temp-file: " + e.toString()); return false; } data.buffer.clear(); } return true; }
From source file:edu.cornell.med.icb.goby.compression.MessageChunksWriter.java
public MessageChunksWriter(final OutputStream output) { this.out = new DataOutputStream(output); compressingCodec = doc.getBoolean("compressing-codec"); final String codecName = doc.getString("codec"); chunkCodec = ChunkCodecHelper.load(codecName); useTemplateCompression = doc.getBoolean("template-compression"); numEntriesPerChunk = doc.getInteger("chunk-size"); if (numEntriesPerChunk == -1) { // if the option was not set, use the chunk codec suggested chunk size: numEntriesPerChunk = chunkCodec.getSuggestedChunkSize(); }//from w w w . ja va 2 s.co m chunkSizeWarning.warn(LOG, "Using chunk-size=" + numEntriesPerChunk); }