List of usage examples for java.io DataOutputStream writeBoolean
public final void writeBoolean(boolean v) throws IOException
boolean
to the underlying output stream as a 1-byte value. From source file:com.igormaznitsa.jhexed.hexmap.HexFieldLayer.java
public void write(final OutputStream out) throws IOException { final DataOutputStream dout = out instanceof DataOutputStream ? (DataOutputStream) out : new DataOutputStream(out); dout.writeUTF(this.name); dout.writeUTF(this.comments); dout.writeShort(this.values.size()); for (int i = 0; i < this.values.size(); i++) { this.values.get(i).write(dout); }/*w w w . j a v a 2 s . c om*/ dout.writeInt(this.columns); dout.writeInt(this.rows); dout.writeBoolean(this.visible); final byte[] packed = Utils.packByteArray(this.array); dout.writeInt(packed.length); dout.write(packed); dout.flush(); }
From source file:epn.edu.ec.bibliotecadigital.servidor.ServerRunnable.java
@Override public void run() { try {//from w ww . j a va 2s . c om DataInputStream dataIn = new DataInputStream(clientSocket.getInputStream()); DataOutputStream dataOut = new DataOutputStream(clientSocket.getOutputStream()); OutputStream out; String accion = dataIn.readUTF(); Libro lbr; String nombreUsuario = dataIn.readUTF(); System.out.println("nombreUsuario" + nombreUsuario); switch (accion) { case "bajar": String codArchivo = dataIn.readUTF(); dataOut = new DataOutputStream(clientSocket.getOutputStream()); lbr = new LibroJpaController(emf).findLibro(Integer.parseInt(codArchivo)); if (lbr == null) { dataOut.writeBoolean(false); break; } dataOut.writeBoolean(true); //File file = new File("C:\\Computacion Distribuida\\" + lbr.getNombre()); dataOut.writeUTF(lbr.getNombre()); out = clientSocket.getOutputStream(); try { byte[] bytes = new byte[64 * 1024]; InputStream in = new ByteArrayInputStream(lbr.getArchivo()); int count; while ((count = in.read(bytes)) > 0) { out.write(bytes, 0, count); } Usuariolibros usrLbr = new Usuariolibros(); usrLbr.setFecha(Calendar.getInstance().getTime()); usrLbr.setAccion('B'); usrLbr.setCodigolibro(lbr); usrLbr.setNombrecuenta(new Usuario(nombreUsuario)); new UsuariolibrosJpaController(emf).create(usrLbr); in.close(); } finally { IOUtils.closeQuietly(out); } break; case "subir": dataIn = new DataInputStream(clientSocket.getInputStream()); String fileName = dataIn.readUTF(); InputStream in = clientSocket.getInputStream(); try { out = new FileOutputStream("C:\\Computacion Distribuida\\" + fileName); byte[] bytes = new byte[64 * 1024]; int count; while ((count = in.read(bytes)) > 0) { out.write(bytes, 0, count); } out.close(); lbr = new Libro(); lbr.setNombre(fileName); lbr.setArchivo( IOUtils.toByteArray(new FileInputStream("C:\\Computacion Distribuida\\" + fileName))); new LibroJpaController(emf).create(lbr); Usuariolibros usrLbr = new Usuariolibros(); usrLbr.setFecha(Calendar.getInstance().getTime()); usrLbr.setAccion('S'); usrLbr.setCodigolibro(lbr); usrLbr.setNombrecuenta(new Usuario(nombreUsuario)); new UsuariolibrosJpaController(emf).create(usrLbr); actualizarLibrosEnServidores(fileName); } finally { IOUtils.closeQuietly(in); } break; case "obtenerLista": ObjectOutputStream outToServer = new ObjectOutputStream(clientSocket.getOutputStream()); outToServer.writeObject(new LibroJpaController(emf).findLibroEntities()); outToServer.close(); break; case "verificarEstado": dataOut.writeUTF(String.valueOf(server.isDisponible())); break; case "actualizar": dataIn = new DataInputStream(clientSocket.getInputStream()); String fileNameFromServer = dataIn.readUTF(); in = clientSocket.getInputStream(); try { out = new FileOutputStream("C:\\Computacion Distribuida\\" + fileNameFromServer); byte[] bytes = new byte[64 * 1024]; int count; while ((count = in.read(bytes)) > 0) { out.write(bytes, 0, count); } out.close(); } catch (IOException e) { e.printStackTrace(); } finally { IOUtils.closeQuietly(in); } } dataIn.close(); } catch (IOException e) { e.printStackTrace(); } }
From source file:ch.unil.genescore.vegas.Snp.java
public void writePosAndAllele(DataOutputStream os) throws IOException { // NOTE: ALSO CHANGE readBinary() IF YOU CHANGE THIS os.writeUTF(id_);/* ww w . ja v a2s .c o m*/ os.writeUTF(chr_); os.writeInt(start_); os.writeInt(end_); os.writeBoolean(posStrand_); os.writeChar(minorAllele_); }
From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java
/** * Serializes a <code>PropertyState</code> to the data output stream * * @param out the output stream//ww w . ja v a2s . c o m * @param state the property entry to store * @throws IOException if an I/O error occurs. */ public void writeState(DataOutputStream out, NodePropBundle.PropertyEntry state) throws IOException { // type & mod count out.writeInt(state.getType() | (state.getModCount() << 16)); // multiValued out.writeBoolean(state.isMultiValued()); // definitionId out.writeUTF(""); // values InternalValue[] values = state.getValues(); out.writeInt(values.length); // count for (int i = 0; i < values.length; i++) { InternalValue val = values[i]; switch (state.getType()) { case PropertyType.BINARY: BLOBFileValue blobVal = val.getBLOBFileValue(); long size = blobVal.getLength(); if (InternalValue.USE_DATA_STORE && dataStore != null) { int maxMemorySize = dataStore.getMinRecordLength() - 1; if (size < maxMemorySize) { writeSmallBinary(out, blobVal, state, i); } else { out.writeInt(BINARY_IN_DATA_STORE); try { val.store(dataStore); } catch (RepositoryException e) { String msg = "Error while storing blob. id=" + state.getId() + " idx=" + i + " size=" + val.getBLOBFileValue().getLength(); log.error(msg, e); throw new IOException(msg); } out.writeUTF(val.toString()); } break; } // special handling required for binary value: // spool binary value to file in blob store if (size < 0) { log.warn("Blob has negative size. Potential loss of data. " + "id={} idx={}", state.getId(), String.valueOf(i)); out.writeInt(0); values[i] = InternalValue.create(new byte[0]); blobVal.discard(); } else if (size > minBlobSize) { out.writeInt(BINARY_IN_BLOB_STORE); String blobId = state.getBlobId(i); if (blobId == null) { try { InputStream in = blobVal.getStream(); try { blobId = blobStore.createId(state.getId(), i); blobStore.put(blobId, in, size); state.setBlobId(blobId, i); } finally { IOUtils.closeQuietly(in); } } catch (Exception e) { String msg = "Error while storing blob. id=" + state.getId() + " idx=" + i + " size=" + size; log.error(msg, e); throw new IOException(msg); } try { // replace value instance with value // backed by resource in blob store and delete temp file if (blobStore instanceof ResourceBasedBLOBStore) { values[i] = InternalValue .create(((ResourceBasedBLOBStore) blobStore).getResource(blobId)); } else { values[i] = InternalValue.create(blobStore.get(blobId)); } } catch (Exception e) { log.error("Error while reloading blob. truncating. id=" + state.getId() + " idx=" + i + " size=" + size, e); values[i] = InternalValue.create(new byte[0]); } blobVal.discard(); } // store id of blob as property value out.writeUTF(blobId); // value } else { // delete evt. blob byte[] data = writeSmallBinary(out, blobVal, state, i); // replace value instance with value // backed by resource in blob store and delete temp file values[i] = InternalValue.create(data); blobVal.discard(); } break; case PropertyType.DOUBLE: out.writeDouble(val.getDouble()); break; case PropertyType.LONG: out.writeLong(val.getLong()); break; case PropertyType.BOOLEAN: out.writeBoolean(val.getBoolean()); break; case PropertyType.NAME: writeQName(out, val.getQName()); break; case PropertyType.REFERENCE: writeUUID(out, val.getUUID()); break; default: // because writeUTF(String) has a size limit of 64k, // we're using write(byte[]) instead byte[] bytes = val.toString().getBytes("UTF-8"); out.writeInt(bytes.length); // length of byte[] out.write(bytes); // byte[] } } }
From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java
/** * Serializes a <code>PropertyState</code> to the data output stream * * @param out the output stream//from www . j a va2s . co m * @param state the property entry to store * @throws IOException if an I/O error occurs. */ public void writeState(DataOutputStream out, NodePropBundle.PropertyEntry state) throws IOException { // type & mod count out.writeInt(state.getType() | (state.getModCount() << 16)); // multiValued out.writeBoolean(state.isMultiValued()); // definitionId out.writeUTF(state.getPropDefId().toString()); // values InternalValue[] values = state.getValues(); out.writeInt(values.length); // count for (int i = 0; i < values.length; i++) { InternalValue val = values[i]; switch (state.getType()) { case PropertyType.BINARY: try { long size = val.getLength(); if (dataStore != null) { int maxMemorySize = dataStore.getMinRecordLength() - 1; if (size < maxMemorySize) { writeSmallBinary(out, val, state, i); } else { out.writeInt(BINARY_IN_DATA_STORE); val.store(dataStore); out.writeUTF(val.toString()); } break; } // special handling required for binary value: // spool binary value to file in blob store if (size < 0) { log.warn("Blob has negative size. Potential loss of data. " + "id={} idx={}", state.getId(), String.valueOf(i)); out.writeInt(0); values[i] = InternalValue.create(new byte[0]); val.discard(); } else if (size > minBlobSize) { out.writeInt(BINARY_IN_BLOB_STORE); String blobId = state.getBlobId(i); if (blobId == null) { try { InputStream in = val.getStream(); try { blobId = blobStore.createId(state.getId(), i); blobStore.put(blobId, in, size); state.setBlobId(blobId, i); } finally { IOUtils.closeQuietly(in); } } catch (Exception e) { String msg = "Error while storing blob. id=" + state.getId() + " idx=" + i + " size=" + size; log.error(msg, e); throw new IOException(msg); } try { // replace value instance with value // backed by resource in blob store and delete temp file if (blobStore instanceof ResourceBasedBLOBStore) { values[i] = InternalValue .create(((ResourceBasedBLOBStore) blobStore).getResource(blobId)); } else { values[i] = InternalValue.create(blobStore.get(blobId)); } } catch (Exception e) { log.error("Error while reloading blob. truncating. id=" + state.getId() + " idx=" + i + " size=" + size, e); values[i] = InternalValue.create(new byte[0]); } val.discard(); } // store id of blob as property value out.writeUTF(blobId); // value } else { // delete evt. blob byte[] data = writeSmallBinary(out, val, state, i); // replace value instance with value // backed by resource in blob store and delete temp file values[i] = InternalValue.create(data); val.discard(); } } catch (RepositoryException e) { String msg = "Error while storing blob. id=" + state.getId() + " idx=" + i + " value=" + val; log.error(msg, e); throw new IOException(msg); } break; case PropertyType.DOUBLE: try { out.writeDouble(val.getDouble()); } catch (RepositoryException e) { // should never occur throw new IOException("Unexpected error while writing DOUBLE value."); } break; case PropertyType.DECIMAL: try { writeDecimal(out, val.getDecimal()); } catch (RepositoryException e) { // should never occur throw new IOException("Unexpected error while writing DECIMAL value."); } break; case PropertyType.LONG: try { out.writeLong(val.getLong()); } catch (RepositoryException e) { // should never occur throw new IOException("Unexpected error while writing LONG value."); } break; case PropertyType.BOOLEAN: try { out.writeBoolean(val.getBoolean()); } catch (RepositoryException e) { // should never occur throw new IOException("Unexpected error while writing BOOLEAN value."); } break; case PropertyType.NAME: try { writeQName(out, val.getName()); } catch (RepositoryException e) { // should never occur throw new IOException("Unexpected error while writing NAME value."); } break; case PropertyType.WEAKREFERENCE: case PropertyType.REFERENCE: writeID(out, val.getNodeId()); break; default: // because writeUTF(String) has a size limit of 64k, // we're using write(byte[]) instead byte[] bytes = val.toString().getBytes("UTF-8"); out.writeInt(bytes.length); // length of byte[] out.write(bytes); // byte[] } } }
From source file:org.apache.jackrabbit.core.persistence.bundle.util.BundleBinding.java
/** * Serializes a <code>PropertyState</code> to the data output stream * * @param out the output stream/*from www . j a v a 2 s . c o m*/ * @param state the property entry to store * @throws IOException if an I/O error occurs. */ public void writeState(DataOutputStream out, NodePropBundle.PropertyEntry state) throws IOException { // type & mod count out.writeInt(state.getType() | (state.getModCount() << 16)); // multiValued out.writeBoolean(state.isMultiValued()); // definitionId out.writeUTF(state.getPropDefId().toString()); // values InternalValue[] values = state.getValues(); out.writeInt(values.length); // count for (int i = 0; i < values.length; i++) { InternalValue val = values[i]; switch (state.getType()) { case PropertyType.BINARY: try { long size = val.getLength(); if (dataStore != null) { int maxMemorySize = dataStore.getMinRecordLength() - 1; if (size < maxMemorySize) { writeSmallBinary(out, val, state, i); } else { out.writeInt(BINARY_IN_DATA_STORE); val.store(dataStore); out.writeUTF(val.toString()); } break; } // special handling required for binary value: // spool binary value to file in blob store if (size < 0) { log.warn("Blob has negative size. Potential loss of data. " + "id={} idx={}", state.getId(), String.valueOf(i)); out.writeInt(0); values[i] = InternalValue.create(new byte[0]); val.discard(); } else if (size > minBlobSize) { out.writeInt(BINARY_IN_BLOB_STORE); String blobId = state.getBlobId(i); if (blobId == null) { try { InputStream in = val.getStream(); try { blobId = blobStore.createId(state.getId(), i); blobStore.put(blobId, in, size); state.setBlobId(blobId, i); } finally { IOUtils.closeQuietly(in); } } catch (Exception e) { String msg = "Error while storing blob. id=" + state.getId() + " idx=" + i + " size=" + size; log.error(msg, e); throw new IOException(msg); } try { // replace value instance with value // backed by resource in blob store and delete temp file if (blobStore instanceof ResourceBasedBLOBStore) { values[i] = InternalValue .create(((ResourceBasedBLOBStore) blobStore).getResource(blobId)); } else { values[i] = InternalValue.create(blobStore.get(blobId)); } } catch (Exception e) { log.error("Error while reloading blob. truncating. id=" + state.getId() + " idx=" + i + " size=" + size, e); values[i] = InternalValue.create(new byte[0]); } val.discard(); } // store id of blob as property value out.writeUTF(blobId); // value } else { // delete evt. blob byte[] data = writeSmallBinary(out, val, state, i); // replace value instance with value // backed by resource in blob store and delete temp file values[i] = InternalValue.create(data); val.discard(); } } catch (RepositoryException e) { String msg = "Error while storing blob. id=" + state.getId() + " idx=" + i + " value=" + val; log.error(msg, e); throw new IOException(msg); } break; case PropertyType.DOUBLE: try { out.writeDouble(val.getDouble()); } catch (RepositoryException e) { // should never occur throw new IOException("Unexpected error while writing DOUBLE value."); } break; case PropertyType.DECIMAL: try { writeDecimal(out, val.getDecimal()); } catch (RepositoryException e) { // should never occur throw new IOException("Unexpected error while writing DECIMAL value."); } break; case PropertyType.LONG: try { out.writeLong(val.getLong()); } catch (RepositoryException e) { // should never occur throw new IOException("Unexpected error while writing LONG value."); } break; case PropertyType.BOOLEAN: try { out.writeBoolean(val.getBoolean()); } catch (RepositoryException e) { // should never occur throw new IOException("Unexpected error while writing BOOLEAN value."); } break; case PropertyType.NAME: try { writeQName(out, val.getName()); } catch (RepositoryException e) { // should never occur throw new IOException("Unexpected error while writing NAME value."); } break; case PropertyType.WEAKREFERENCE: case PropertyType.REFERENCE: writeUUID(out, val.getUUID()); break; default: // because writeUTF(String) has a size limit of 64k, // we're using write(byte[]) instead byte[] bytes = val.toString().getBytes("UTF-8"); out.writeInt(bytes.length); // length of byte[] out.write(bytes); // byte[] } } }
From source file:org.structr.core.graph.SyncCommand.java
private static void writeObject(final DataOutputStream outputStream, final byte type, final Object value) throws IOException { switch (type) { case 0:// w w w . java 2s . c o m case 1: outputStream.writeByte((byte) value); break; case 2: case 3: outputStream.writeShort((short) value); break; case 4: case 5: outputStream.writeInt((int) value); break; case 6: case 7: outputStream.writeLong((long) value); break; case 8: case 9: outputStream.writeFloat((float) value); break; case 10: case 11: outputStream.writeDouble((double) value); break; case 12: case 13: outputStream.writeChar((char) value); break; case 14: case 15: serializeData(outputStream, ((String) value).getBytes("UTF-8")); // this doesn't work with very long strings //outputStream.writeUTF((String)value); break; case 16: case 17: outputStream.writeBoolean((boolean) value); break; } }
From source file:eu.stratosphere.nephele.ipc.Server.java
/** * Setup response for the IPC Call.// w w w . ja va2s. co m * * @param response * buffer to serialize the response into * @param call * {@link Call} to which we are setting up the response * @param status * {@link Status} of the IPC call * @param rv * return value for the IPC Call, if the call was successful * @param errorClass * error class, if the the call failed * @param error * error message, if the call failed * @throws IOException */ private void setupResponse(ByteArrayOutputStream response, Call call, Status status, IOReadableWritable rv, String errorClass, String error) throws IOException { response.reset(); DataOutputStream out = new DataOutputStream(response); out.writeInt(call.id); // write call id out.writeInt(status.state); // write status if (status == Status.SUCCESS) { if (rv == null) { out.writeBoolean(false); } else { out.writeBoolean(true); StringRecord.writeString(out, rv.getClass().getName()); rv.write(out); } } else { StringRecord.writeString(out, errorClass); StringRecord.writeString(out, error); } call.setResponse(ByteBuffer.wrap(response.toByteArray())); }
From source file:org.apache.flink.runtime.ipc.Server.java
/** * Setup response for the IPC Call.//from ww w.j a v a2 s. com * * @param response * buffer to serialize the response into * @param call * {@link Call} to which we are setting up the response * @param status * {@link Status} of the IPC call * @param rv * return value for the IPC Call, if the call was successful * @param errorClass * error class, if the the call failed * @param error * error message, if the call failed * @throws IOException */ private void setupResponse(ByteArrayOutputStream response, Call call, Status status, IOReadableWritable rv, String errorClass, String error) throws IOException { response.reset(); DataOutputStream out = new DataOutputStream(response); out.writeInt(call.id); // write call id out.writeInt(status.state); // write status if (status == Status.SUCCESS) { if (rv == null) { out.writeBoolean(false); } else { out.writeBoolean(true); StringRecord.writeString(out, rv.getClass().getName()); rv.write(new OutputViewDataOutputStreamWrapper(out)); } } else { StringRecord.writeString(out, errorClass); StringRecord.writeString(out, error); } call.setResponse(ByteBuffer.wrap(response.toByteArray())); }
From source file:MersenneTwisterFast.java
/** Writes the entire state of the MersenneTwister RNG to the stream * @param stream output stream/* w w w . jav a 2 s. c o m*/ * @throws IOException exception from stream reading */ public void writeState(DataOutputStream stream) throws IOException { int len = mt.length; for (int x = 0; x < len; x++) stream.writeInt(mt[x]); len = mag01.length; for (int x = 0; x < len; x++) stream.writeInt(mag01[x]); stream.writeInt(mti); stream.writeDouble(__nextNextGaussian); stream.writeBoolean(__haveNextNextGaussian); }