List of usage examples for java.io DataOutputStream write
public synchronized void write(int b) throws IOException
b
) to the underlying output stream. From source file:org.apache.hadoop.security.Credentials.java
public void writeTokenStorageToStream(DataOutputStream os) throws IOException { os.write(TOKEN_STORAGE_MAGIC); os.write(TOKEN_STORAGE_VERSION);//from w w w .ja v a2 s.com write(os); }
From source file:com.haulmont.yarg.formatters.impl.HtmlFormatter.java
protected void renderPdfDocument(String htmlContent, OutputStream outputStream) { ITextRenderer renderer = new ITextRenderer(); File temporaryFile = null;/*from w w w. j a v a 2 s .c o m*/ try { temporaryFile = File.createTempFile("htmlReport", ".htm"); DataOutputStream dataOutputStream = new DataOutputStream(new FileOutputStream(temporaryFile)); dataOutputStream.write(htmlContent.getBytes(Charset.forName("UTF-8"))); dataOutputStream.close(); String url = temporaryFile.toURI().toURL().toString(); renderer.setDocument(url); renderer.layout(); renderer.createPDF(outputStream); } catch (Exception e) { throw wrapWithReportingException("", e); } finally { FileUtils.deleteQuietly(temporaryFile); } }
From source file:org.openecomp.sdnc.dmaapclient.SdncOdlConnection.java
public String send(String method, String contentType, String msg) throws IOException { LOG.info("Sending REST " + method + " to " + url); LOG.info("Message body:\n" + msg); String authStr = user + ":" + password; String encodedAuthStr = new String(Base64.encodeBase64(authStr.getBytes())); httpConn.addRequestProperty("Authentication", "Basic " + encodedAuthStr); httpConn.setRequestMethod(method);/*from w w w .ja v a2s .c o m*/ httpConn.setRequestProperty("Content-Type", contentType); httpConn.setRequestProperty("Accept", contentType); httpConn.setDoInput(true); httpConn.setDoOutput(true); httpConn.setUseCaches(false); if (httpConn instanceof HttpsURLConnection) { HostnameVerifier hostnameVerifier = new HostnameVerifier() { @Override public boolean verify(String hostname, SSLSession session) { return true; } }; ((HttpsURLConnection) httpConn).setHostnameVerifier(hostnameVerifier); } // Write message httpConn.setRequestProperty("Content-Length", "" + msg.length()); DataOutputStream outStr = new DataOutputStream(httpConn.getOutputStream()); outStr.write(msg.getBytes()); outStr.close(); // Read response BufferedReader respRdr; LOG.info("Response: " + httpConn.getResponseCode() + " " + httpConn.getResponseMessage()); if (httpConn.getResponseCode() < 300) { respRdr = new BufferedReader(new InputStreamReader(httpConn.getInputStream())); } else { respRdr = new BufferedReader(new InputStreamReader(httpConn.getErrorStream())); } StringBuffer respBuff = new StringBuffer(); String respLn; while ((respLn = respRdr.readLine()) != null) { respBuff.append(respLn + "\n"); } respRdr.close(); String respString = respBuff.toString(); LOG.info("Response body :\n" + respString); return (respString); }
From source file:com.example.chengcheng.network.httpstacks.HttpUrlConnStack.java
protected void setRequestParams(HttpURLConnection connection, Request<?> request) throws ProtocolException, IOException { Request.HttpMethod method = request.getmHttpMethod(); connection.setRequestMethod(method.toString()); // add params byte[] body = request.getBody(); if (body != null) { // enable output connection.setDoOutput(true);/* w ww.j a va 2 s. com*/ // set content type connection.addRequestProperty(Request.HEADER_CONTENT_TYPE, request.getBodyContentType()); // write params data to connection DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream()); dataOutputStream.write(body); dataOutputStream.close(); } }
From source file:org.simple.net.httpstacks.HttpUrlConnStack.java
protected void setRequestParams(HttpURLConnection connection, Request<?> request) throws ProtocolException, IOException { HttpMethod method = request.getHttpMethod(); connection.setRequestMethod(method.toString()); // add params byte[] body = request.getBody(); if (body != null) { // enable output connection.setDoOutput(true);//ww w . j a v a 2 s. c o m // set content type connection.addRequestProperty(Request.HEADER_CONTENT_TYPE, request.getBodyContentType()); // write params data to connection DataOutputStream dataOutputStream = new DataOutputStream(connection.getOutputStream()); dataOutputStream.write(body); dataOutputStream.close(); } }
From source file:mitm.common.security.crypto.PBEncryptedStreamParameters.java
/** * Returns the encoded form of PBEncryptionParameters. *///from w ww . j a va 2s .c om public byte[] getEncoded() throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream out = new DataOutputStream(bos); out.writeLong(serialVersionUID); out.writeUTF(algorithm); out.writeInt(salt.length); out.write(salt); out.writeInt(iterationCount); return bos.toByteArray(); }
From source file:com.davidcode.code.util.ErrorBuffer.java
/** * Writes the data to a socket using prehistoric java * * @param socket/*from w ww . ja va 2 s. co m*/ * @throws IOException */ public void write(Socket socket) throws IOException { //Get the data in byte form byte[] outputBuf = asByteArray(); outputBuf = xor(outputBuf); //Write the data to the socket which is connected to a server for recieving this data DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream()); dataOutputStream.write(outputBuf); //Flush and close the stream dataOutputStream.flush(); dataOutputStream.close(); }
From source file:org.getspout.spout.packet.PacketCustomBlockChunkOverride.java
public void writeData(DataOutputStream output) throws IOException { output.writeInt(chunkX);//from ww w. ja v a2 s .c o m output.writeInt(chunkZ); output.writeInt(data.length); output.write(data); }
From source file:cc.aileron.commons.resource.ResourceImpl.java
/** * @return byte[]/* w w w . java2s . c o m*/ * @throws IOException */ @Override public byte[] toBytes() throws IOException { final BufferedInputStream in = new BufferedInputStream(content.getInputStream()); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final DataOutputStream os = new DataOutputStream(baos); byte[] buffer = new byte[8192]; while (in.read(buffer) != -1) { os.write(buffer); buffer = new byte[8192]; } return baos.toByteArray(); }
From source file:com.igormaznitsa.jhexed.values.HexSVGImageValue.java
@Override public void write(final OutputStream out) throws IOException { out.write(TYPE_SVGIMAGE);//from ww w. ja v a 2 s.c o m super.write(out); final ByteArrayOutputStream imageDataBuffer = new ByteArrayOutputStream(4096); this.image.write(imageDataBuffer, true); final byte[] imageData = imageDataBuffer.toByteArray(); final DataOutputStream dout = out instanceof DataOutputStream ? (DataOutputStream) out : new DataOutputStream(out); dout.writeInt(imageData.length); dout.write(imageData); }