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:com.vimc.ahttp.HurlWorker.java
private void writeDataStart(DataOutputStream out, String paramaName, String fileName, String boundary) throws IOException { StringBuffer sb = new StringBuffer(); sb.append(TWO_HYPHENS);//from w ww . j ava 2s .c om sb.append(boundary); sb.append(LINE_END); sb.append("Content-Disposition: form-data; name=\"" + paramaName + "\"; filename=\"" + fileName + "\"" + LINE_END); sb.append("Content-Type: application/octet-stream; charset=" + "utf-8" + LINE_END); sb.append(LINE_END); out.write(sb.toString().getBytes()); }
From source file:com.kitware.tangoproject.paraviewtangorecorder.PointCloudActivity.java
private void writePointCloudToFile(TangoXyzIjData xyzIj, byte[] buffer, ArrayList<TangoCoordinateFramePair> framePairs) { ByteBuffer myBuffer = ByteBuffer.allocate(xyzIj.xyzCount * 3 * 4); myBuffer.order(ByteOrder.LITTLE_ENDIAN); myBuffer.put(buffer, xyzIj.xyzParcelFileDescriptorOffset, myBuffer.capacity()); File mainDir = new File(mMainDirPath); if (!mainDir.exists()) { boolean created = mainDir.mkdir(); if (created) { Log.i(TAG, "Folder: \"" + mMainDirPath + "\" created\n"); }/*from ww w .j a v a2 s . c o m*/ } File dir = new File(mSaveDirAbsPath); if (!dir.exists()) { boolean created = dir.mkdir(); if (created) { Log.i(TAG, "Folder: \"" + mSaveDirAbsPath + "\" created\n"); } } mFilename = "pc_" + mNowTimeString + "_" + String.format("%03d", mNumberOfFilesWritten) + ".vtk"; mFilenameBuffer.add(mSaveDirAbsPath + mFilename); File file = new File(dir, mFilename); try { DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file))); out.write(("# vtk DataFile Version 3.0\n" + "vtk output\n" + "BINARY\n" + "DATASET POLYDATA\n" + "POINTS " + xyzIj.xyzCount + " float\n").getBytes()); for (int i = 0; i < xyzIj.xyzCount; i++) { out.writeFloat(myBuffer.getFloat(3 * i * 4)); out.writeFloat(myBuffer.getFloat((3 * i + 1) * 4)); out.writeFloat(myBuffer.getFloat((3 * i + 2) * 4)); } out.write(("\nVERTICES 1 " + String.valueOf(xyzIj.xyzCount + 1) + "\n").getBytes()); out.writeInt(xyzIj.xyzCount); for (int i = 0; i < xyzIj.xyzCount; i++) { out.writeInt(i); } out.write(("\nFIELD FieldData 1\n" + "timestamp 1 1 float\n").getBytes()); out.writeFloat((float) xyzIj.timestamp); out.close(); mNumberOfFilesWritten++; mTimeToTakeSnap = false; } catch (IOException e) { e.printStackTrace(); } }
From source file:com.kitware.tangoproject.paraviewtangorecorder.PointCloudActivity.java
private void writePoseToFile(int numPoints) { File mainDir = new File(mMainDirPath); if (!mainDir.exists()) { boolean created = mainDir.mkdir(); if (created) { Log.i(TAG, "Folder: \"" + mMainDirPath + "\" created\n"); }//from w w w .j a v a2s .co m } File dir = new File(mSaveDirAbsPath); if (!dir.exists()) { boolean created = dir.mkdir(); if (created) { Log.i(TAG, "Folder: \"" + mSaveDirAbsPath + "\" created\n"); } } String poseFileName = "pc_" + mNowTimeString + "_poses.vtk"; mFilenameBuffer.add(mSaveDirAbsPath + poseFileName); File file = new File(dir, poseFileName); try { DataOutputStream out = new DataOutputStream(new BufferedOutputStream(new FileOutputStream(file))); out.write(("# vtk DataFile Version 3.0\n" + "vtk output\n" + "BINARY\n" + "DATASET POLYDATA\n" + "POINTS " + numPoints + " float\n").getBytes()); for (int i = 0; i < numPoints; i++) { out.writeFloat(mPosePositionBuffer.get(i)[0]); out.writeFloat(mPosePositionBuffer.get(i)[1]); out.writeFloat(mPosePositionBuffer.get(i)[2]); } out.write(("\nLINES 1 " + String.valueOf(numPoints + 1) + "\n").getBytes()); out.writeInt(numPoints); for (int i = 0; i < numPoints; i++) { out.writeInt(i); } out.write(("\nPOINT_DATA " + String.valueOf(numPoints) + "\n" + "FIELD FieldData 2\n" + "orientation 4 " + String.valueOf(numPoints) + " float\n").getBytes()); for (int i = 0; i < numPoints; i++) { out.writeFloat(mPoseOrientationBuffer.get(i)[0]); out.writeFloat(mPoseOrientationBuffer.get(i)[1]); out.writeFloat(mPoseOrientationBuffer.get(i)[2]); out.writeFloat(mPoseOrientationBuffer.get(i)[3]); } out.write(("\ntimestamp 1 " + String.valueOf(numPoints) + " float\n").getBytes()); for (int i = 0; i < numPoints; i++) { out.writeFloat(mPoseTimestampBuffer.get(i)); } out.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:com.chaosinmotion.securechat.server.messages.NotificationSocket.java
/** * Internal method for sending a message to the specified device. This * encodes the message as a binary array and transmits it as a single * packet to the listening device. This allows users to receive messages * during chat as soon as we are able to, for (more or less) just in time * messaging.//ww w . j a va 2s . c om * * The packet returned here is similar to the packet returned by the * getmessages api, except we serialize as binary. * * @param messageid * @param senderid * @param sendername * @param ts * @param message * @throws IOException */ void sendMessage(int messageid, int senderid, String sendername, boolean toflag, Timestamp ts, byte[] message) throws IOException { ByteArrayOutputStream baos = new ByteArrayOutputStream(); DataOutputStream dos = new DataOutputStream(baos); /* * Encode. First byte is 0x20 */ String date; synchronized (format) { date = format.format(ts); } /* * Formulate packet in expected format */ dos.writeByte(0x20); // marker dos.writeBoolean(toflag); dos.writeInt(messageid); dos.writeInt(senderid); dos.writeUTF(date); dos.writeUTF(sendername); dos.writeInt(message.length); dos.write(message); /* * Flush and write packet to device. Our protocol does not depend on * the device actually receiving this message, as we wait until the * device deletes the messages by a separate command. */ dos.flush(); out.writeData(baos.toByteArray()); }
From source file:bobs.is.compress.sevenzip.SevenZOutputFile.java
private void writeFileATimes(final DataOutput header) throws IOException { int numAccessDates = 0; for (final SevenZArchiveEntry entry : files) { if (entry.getHasAccessDate()) { ++numAccessDates;/*from ww w .java 2s. c om*/ } } if (numAccessDates > 0) { header.write(NID.kATime); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final DataOutputStream out = new DataOutputStream(baos); if (numAccessDates != files.size()) { out.write(0); final BitSet aTimes = new BitSet(files.size()); for (int i = 0; i < files.size(); i++) { aTimes.set(i, files.get(i).getHasAccessDate()); } writeBits(out, aTimes, files.size()); } else { out.write(1); // "allAreDefined" == true } out.write(0); for (final SevenZArchiveEntry entry : files) { if (entry.getHasAccessDate()) { out.writeLong(Long.reverseBytes(SevenZArchiveEntry.javaTimeToNtfsTime(entry.getAccessDate()))); } } out.flush(); final byte[] contents = baos.toByteArray(); writeUint64(header, contents.length); header.write(contents); } }
From source file:com.linkedin.pinot.core.common.datatable.DataTableImplV2.java
private byte[] serializeMetadata() throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); DataOutputStream dataOutputStream = new DataOutputStream(byteArrayOutputStream); dataOutputStream.writeInt(_metadata.size()); for (Entry<String, String> entry : _metadata.entrySet()) { byte[] keyBytes = entry.getKey().getBytes(UTF_8); dataOutputStream.writeInt(keyBytes.length); dataOutputStream.write(keyBytes); byte[] valueBytes = entry.getValue().getBytes(UTF_8); dataOutputStream.writeInt(valueBytes.length); dataOutputStream.write(valueBytes); }/*from w w w.j a va2 s . c om*/ return byteArrayOutputStream.toByteArray(); }
From source file:bobs.is.compress.sevenzip.SevenZOutputFile.java
private void writeFileCTimes(final DataOutput header) throws IOException { int numCreationDates = 0; for (final SevenZArchiveEntry entry : files) { if (entry.getHasCreationDate()) { ++numCreationDates;// w w w .j a v a 2s .c o m } } if (numCreationDates > 0) { header.write(NID.kCTime); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final DataOutputStream out = new DataOutputStream(baos); if (numCreationDates != files.size()) { out.write(0); final BitSet cTimes = new BitSet(files.size()); for (int i = 0; i < files.size(); i++) { cTimes.set(i, files.get(i).getHasCreationDate()); } writeBits(out, cTimes, files.size()); } else { out.write(1); // "allAreDefined" == true } out.write(0); for (final SevenZArchiveEntry entry : files) { if (entry.getHasCreationDate()) { out.writeLong( Long.reverseBytes(SevenZArchiveEntry.javaTimeToNtfsTime(entry.getCreationDate()))); } } out.flush(); final byte[] contents = baos.toByteArray(); writeUint64(header, contents.length); header.write(contents); } }
From source file:bobs.is.compress.sevenzip.SevenZOutputFile.java
private void writeFileWindowsAttributes(final DataOutput header) throws IOException { int numWindowsAttributes = 0; for (final SevenZArchiveEntry entry : files) { if (entry.getHasWindowsAttributes()) { ++numWindowsAttributes;// ww w. j a v a 2 s. c o m } } if (numWindowsAttributes > 0) { header.write(NID.kWinAttributes); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final DataOutputStream out = new DataOutputStream(baos); if (numWindowsAttributes != files.size()) { out.write(0); final BitSet attributes = new BitSet(files.size()); for (int i = 0; i < files.size(); i++) { attributes.set(i, files.get(i).getHasWindowsAttributes()); } writeBits(out, attributes, files.size()); } else { out.write(1); // "allAreDefined" == true } out.write(0); for (final SevenZArchiveEntry entry : files) { if (entry.getHasWindowsAttributes()) { out.writeInt(Integer.reverseBytes(entry.getWindowsAttributes())); } } out.flush(); final byte[] contents = baos.toByteArray(); writeUint64(header, contents.length); header.write(contents); } }
From source file:bobs.is.compress.sevenzip.SevenZOutputFile.java
private void writeFileMTimes(final DataOutput header) throws IOException { int numLastModifiedDates = 0; for (final SevenZArchiveEntry entry : files) { if (entry.getHasLastModifiedDate()) { ++numLastModifiedDates;//from w w w. ja v a 2s . c o m } } if (numLastModifiedDates > 0) { header.write(NID.kMTime); final ByteArrayOutputStream baos = new ByteArrayOutputStream(); final DataOutputStream out = new DataOutputStream(baos); if (numLastModifiedDates != files.size()) { out.write(0); final BitSet mTimes = new BitSet(files.size()); for (int i = 0; i < files.size(); i++) { mTimes.set(i, files.get(i).getHasLastModifiedDate()); } writeBits(out, mTimes, files.size()); } else { out.write(1); // "allAreDefined" == true } out.write(0); for (final SevenZArchiveEntry entry : files) { if (entry.getHasLastModifiedDate()) { out.writeLong( Long.reverseBytes(SevenZArchiveEntry.javaTimeToNtfsTime(entry.getLastModifiedDate()))); } } out.flush(); final byte[] contents = baos.toByteArray(); writeUint64(header, contents.length); header.write(contents); } }
From source file:org.fenixedu.parking.ui.Action.ParkingManagerDispatchAction.java
public ActionForward showPhoto(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { Party party = FenixFramework.getDomainObject(request.getParameter("personID")); if (party.isPerson()) { Person person = (Person) party;//from w w w . ja v a 2 s . c o m Photograph personalPhoto = person.getPersonalPhoto(); if (personalPhoto != null) { try { byte[] avatar = personalPhoto.getDefaultAvatar(); response.setContentType(ContentType.PNG.getMimeType()); DataOutputStream dos = new DataOutputStream(response.getOutputStream()); dos.write(avatar); dos.close(); } catch (java.io.IOException e) { throw new FenixActionException(e); } } } return null; }