List of usage examples for java.io ObjectOutputStream writeLong
public void writeLong(long val) throws IOException
From source file:Main.java
public static void main(String[] args) throws Exception { long l = 12345678909876L; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeLong(l); oout.writeLong(987654321L);//from w w w . j ava 2 s . co m oout.flush(); oout.close(); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); System.out.println(ois.readLine()); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { long l = 12345678909876L; FileOutputStream out = new FileOutputStream("test.txt"); ObjectOutputStream oout = new ObjectOutputStream(out); // write something in the file oout.writeLong(l); oout.writeLong(987654321L);/*from w ww .j a v a 2s. co m*/ oout.flush(); oout.close(); // create an ObjectInputStream for the file we created before ObjectInputStream ois = new ObjectInputStream(new FileInputStream("test.txt")); // read and print a long System.out.println(ois.readLong()); // read and print a long System.out.println(ois.readLong()); ois.close(); }
From source file:Main.java
public static void main(String[] args) throws Exception { ObjectOutputStream out = new ObjectOutputStream( new BufferedOutputStream(new FileOutputStream("file.data"))); out.writeLong(1111111111111L); out.close();/*from w ww . ja va 2s .c o m*/ ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream("file.data"))); byte[] byteArray = new byte[10]; in.read(byteArray); System.out.println(Arrays.toString(byteArray)); in.close(); }
From source file:jfs.sync.encryption.JFSEncryptedStream.java
public static OutputStream createOutputStream(long compressionLimit, OutputStream baseOutputStream, long length, Cipher cipher) throws IOException { OutputStream result = null;//w w w.j a va 2 s . co m Runtime runtime = Runtime.getRuntime(); long freeMem = runtime.totalMemory() / SPACE_RESERVE; if (length >= freeMem) { if (log.isWarnEnabled()) { log.warn("JFSEncryptedStream.createOutputStream() GC " + freeMem + "/" + runtime.maxMemory()); } // if runtime.gc(); freeMem = runtime.totalMemory() / SPACE_RESERVE; } // if if ((length < compressionLimit) && (length < freeMem)) { result = new JFSEncryptedStream(baseOutputStream, cipher); } else { if (length < freeMem) { if (log.isInfoEnabled()) { log.info("JFSEncryptedStream.createOutputStream() not compressing"); } // if } else { if (log.isWarnEnabled()) { log.warn("JFSEncryptedStream.createOutputStream() due to memory constraints (" + length + "/" + freeMem + ") not compressing"); } // if } // if ObjectOutputStream oos = new ObjectOutputStream(baseOutputStream); oos.writeByte(COMPRESSION_NONE); oos.writeLong(length); oos.flush(); result = baseOutputStream; if (cipher != null) { result = new CipherOutputStream(result, cipher); } // if } // if return result; }
From source file:mitm.application.djigzo.mail.MailContainer.java
private void writeObject(ObjectOutputStream out) throws IOException { out.writeLong(serialVersionUID); out.writeObject(mail); }
From source file:mitm.application.djigzo.james.EncryptedContainer.java
private void writeObject(ObjectOutputStream out) throws IOException, EncryptorException { out.writeLong(serialVersionUID); byte[] encrypted = getEncryptor().encrypt(SerializationUtils.serialize(value)); out.writeInt(ArrayUtils.getLength(encrypted)); out.write(encrypted);// www. java 2s . c o m }
From source file:mitm.application.djigzo.james.Certificates.java
private void writeObject(ObjectOutputStream out) throws IOException { try {/* ww w .ja v a 2 s. c o m*/ out.writeLong(serialVersionUID); /* * Write the number of certificates so we know how many we have to read when deserializing. */ out.writeInt(certificates.size()); for (X509Certificate certificate : certificates) { byte[] encoded = certificate.getEncoded(); /* * write the size of the encoded certificate so we can restore it */ out.writeInt(encoded.length); out.write(certificate.getEncoded()); } } catch (CertificateEncodingException e) { throw new IOException(e); } }
From source file:com.qwazr.utils.server.InFileSessionPersistenceManager.java
private void writeSession(File deploymentDir, String sessionId, PersistentSession persistentSession) { final Date expDate = persistentSession.getExpiration(); if (expDate == null) return; // No expiry date? no serialization final Map<String, Object> sessionData = persistentSession.getSessionData(); if (sessionData == null || sessionData.isEmpty()) return; // No attribute? no serialization File sessionFile = new File(deploymentDir, sessionId); try {//ww w .j av a 2 s . c o m final FileOutputStream fileOutputStream = new FileOutputStream(sessionFile); try { final ObjectOutputStream out = new ObjectOutputStream(fileOutputStream); try { out.writeLong(expDate.getTime()); // The date is stored as long sessionData.forEach((attribute, object) -> writeSessionAttribute(out, attribute, object)); } finally { IOUtils.close(out); } } finally { IOUtils.close(fileOutputStream); } } catch (IOException e) { if (logger.isWarnEnabled()) logger.warn("Cannot save sessions in " + sessionFile + " " + e.getMessage(), e); } }
From source file:hudson.console.AnnotatedLargeText.java
public long writeHtmlTo(long start, Writer w) throws IOException { ConsoleAnnotationOutputStream caw = new ConsoleAnnotationOutputStream(w, createAnnotator(Stapler.getCurrentRequest()), context, charset); long r = super.writeLogTo(start, caw); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Cipher sym = PASSING_ANNOTATOR.encrypt(); ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(new CipherOutputStream(baos, sym))); oos.writeLong(System.currentTimeMillis()); // send timestamp to prevent a replay attack oos.writeObject(caw.getConsoleAnnotator()); oos.close();/*from www . j ava 2s. c om*/ StaplerResponse rsp = Stapler.getCurrentResponse(); if (rsp != null) rsp.setHeader("X-ConsoleAnnotator", new String(Base64.encode(baos.toByteArray()))); return r; }
From source file:at.molindo.esi4j.rebuild.scrutineer.ObjectIdAndVersion.java
@Override protected void writeId(ObjectOutputStream objectOutputStream) throws IOException { if (_id instanceof String) { objectOutputStream.writeBoolean(true); objectOutputStream.writeUTF((String) _id); } else {// w w w .j a v a 2 s . c o m objectOutputStream.writeBoolean(false); objectOutputStream.writeLong(((Number) _id).longValue()); } }