List of usage examples for java.io ObjectOutputStream writeLong
public void writeLong(long val) throws IOException
From source file:org.apache.hawq.pxf.plugins.hdfs.utilities.HdfsUtilities.java
/** * Prepares byte serialization of a file split information (start, length, * hosts) using {@link ObjectOutputStream}. * * @param fsp file split to be serialized * @return byte serialization of fsp/* w w w . j a v a2s . co m*/ * @throws IOException if I/O errors occur while writing to the underlying * stream */ public static byte[] prepareFragmentMetadata(FileSplit fsp) throws IOException { ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); ObjectOutputStream objectStream = new ObjectOutputStream(byteArrayStream); objectStream.writeLong(fsp.getStart()); objectStream.writeLong(fsp.getLength()); objectStream.writeObject(fsp.getLocations()); return byteArrayStream.toByteArray(); }
From source file:org.apache.openjpa.event.TCPRemoteCommitProvider.java
public void broadcast(RemoteCommitEvent event) { try {/*from w w w .jav a 2 s . co m*/ // build a packet notifying other JVMs of object changes. ByteArrayOutputStream baos = new ByteArrayOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(baos); oos.writeLong(PROTOCOL_VERSION); oos.writeLong(_id); oos.writeInt(_port); oos.writeObject(_localhost); oos.writeObject(event); oos.flush(); byte[] bytes = baos.toByteArray(); baos.close(); if (_broadcastThreads.isEmpty()) sendUpdatePacket(bytes); else _broadcastQueue.addPacket(bytes); } catch (IOException ioe) { if (log.isWarnEnabled()) log.warn(s_loc.get("tcp-payload-create-error"), ioe); } }
From source file:org.codehaus.wadi.core.store.DiscStore.java
public void insert(Motable motable) throws Exception { File file = new File(sessionStoreDir, motable.getId() + streamer.getSuffixWithDot()); ObjectOutputStream oos = null; FileOutputStream fos = null;/*from www . j a va 2 s. com*/ try { fos = new FileOutputStream(file); oos = new ObjectOutputStream(fos); oos.writeLong(motable.getCreationTime()); oos.writeLong(motable.getLastAccessedTime()); oos.writeInt(motable.getMaxInactiveInterval()); oos.writeObject(motable.getId()); byte[] bodyAsByteArray = motable.getBodyAsByteArray(); oos.writeInt(bodyAsByteArray.length); oos.flush(); if (bodyAsByteArray.length > 0) { fos.write(bodyAsByteArray); } if (log.isTraceEnabled()) { log.trace("stored disc motable): " + file + ": " + bodyAsByteArray.length + " bytes"); } } catch (Exception e) { log.warn("store exclusive disc failed. File [" + file + "]", e); throw e; } finally { try { if (oos != null) { oos.close(); } } catch (IOException e) { log.warn("store exclusive disc) problem. File [" + file + "]", e); } } }
From source file:org.jenkinsci.plugins.fabric8.support.hack.AnnotatedLargeText.java
public long writeHtmlTo(long start, Writer w) throws IOException { ConsoleAnnotationOutputStream caw = new ConsoleAnnotationOutputStream(w, this.createAnnotator(Stapler.getCurrentRequest()), this.context, this.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()); oos.writeObject(caw.getConsoleAnnotator()); oos.close();// w w w. j a v a 2 s.c om StaplerResponse rsp = Stapler.getCurrentResponse(); if (rsp != null) { rsp.setHeader("X-ConsoleAnnotator", new String(Base64.encode(baos.toByteArray()))); } return r; }
From source file:org.jenkinsci.plugins.fabric8.support.hack.AnnotatedLargeText.java
@Override public long writeLogTo(long start, int size, Writer w) throws IOException { if (isHtml()) { ConsoleAnnotationOutputStream caw = new ConsoleAnnotationOutputStream(w, this.createAnnotator(Stapler.getCurrentRequest()), this.context, this.charset); long r = super.writeLogTo(start, size, caw); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Cipher sym = PASSING_ANNOTATOR.encrypt(); ObjectOutputStream oos = new ObjectOutputStream( new GZIPOutputStream(new CipherOutputStream(baos, sym))); oos.writeLong(System.currentTimeMillis()); oos.writeObject(caw.getConsoleAnnotator()); oos.close();//from w ww . j a va2 s . com StaplerResponse rsp = Stapler.getCurrentResponse(); if (rsp != null) { rsp.setHeader("X-ConsoleAnnotator", new String(Base64.encode(baos.toByteArray()))); } return r; } else { return super.writeLogTo(start, size, w); } }
From source file:org.largecollections.LargeCacheMap.java
private void writeObject(java.io.ObjectOutputStream stream) throws IOException { stream.writeObject(this.folder); stream.writeObject(this.name); stream.writeInt(this.cacheSize); stream.writeObject(this.dbComparatorCls); stream.writeInt(this.size); stream.writeLong(this.longSize); this.db.close(); }
From source file:org.opendas.calendar.Settings.java
/** * Save GUI settings// w ww. j a v a2 s .c o m * * @param x * x position of main frame on screen * @param y * y position of main frame on screen * @param width * main frame width * @param sh * slot height * @param dh * main frame decoration height * @param nor_hours * number of rendered hours * @param eview * false - simple view, true - extended view<br> * @param rl * false - don't show row labels, true - show it<br> * */ public void save_gui_settings(int x, int y, int width, int sh, int dh, long nor_hours, boolean eview, boolean rl) { frame_x = x; frame_y = y; frame_width = width; slot_height = sh; decor_height = dh; number_of_rendered_hours = nor_hours; ext_view = eview; show_row_labels = rl; try { new File(gui_settings_file_name).delete(); ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(gui_settings_file_name)); out.writeInt(x); out.writeInt(y); out.writeInt(width); out.writeInt(sh); out.writeInt(dh); out.writeLong(nor_hours); out.writeBoolean(eview); out.writeBoolean(rl); out.close(); } catch (Exception b) { b.printStackTrace(); } }
From source file:org.pentaho.reporting.engine.classic.core.Element.java
/** * A helper method that serializes the element object. * * @param stream//w w w.ja v a2s . co m * the stream to which the element should be serialized. * @throws IOException * if an IO error occured or a property was not serializable. */ private void writeObject(final ObjectOutputStream stream) throws IOException { stream.defaultWriteObject(); final ReportAttributeMap attributes = this.attributes; stream.writeLong(attributes.getChangeTracker()); final String[] nameSpaces = attributes.getNameSpaces(); stream.writeObject(nameSpaces); for (int i = 0; i < nameSpaces.length; i++) { final String nameSpace = nameSpaces[i]; final String[] names = attributes.getNames(nameSpace); stream.writeObject(names); for (int j = 0; j < names.length; j++) { final String name = names[j]; final Object attribute = attributes.getAttribute(nameSpace, name); final AttributeMetaData data = getMetaData().getAttributeDescription(nameSpace, name); if (data != null) { if (data.isTransient()) { stream.writeByte(1); continue; } if (attribute instanceof ResourceKey) { final ResourceKey key = (ResourceKey) attribute; final ResourceKey parent = key.getParent(); if (AttributeNames.Core.NAMESPACE.equals(nameSpace) && (AttributeNames.Core.CONTENT_BASE.equals(name) || AttributeNames.Core.SOURCE.equals(name))) { if (parent != null) { // unwrap the content base attribute. After deserialization, the report assumes the bundle-location // as content base, as the bundle will be gone. if (isKeySerializable(parent)) { stream.writeByte(0); SerializerHelper.getInstance().writeObject(parent, stream); } else { stream.writeByte(1); } } else { // great, the report was never part of a bundle. That makes life easier and the key should be // safely serializable too. if (isKeySerializable(key)) { stream.writeByte(0); SerializerHelper.getInstance().writeObject(key, stream); } else { stream.writeByte(1); } } } else { if ("Resource".equals(data.getValueRole()) || parent != null) { stream.writeByte(0); try { final ResourceKey resourceKey = ResourceKeyUtils.embedResourceInKey( locateResourceManager(), key, key.getFactoryParameters()); SerializerHelper.getInstance().writeObject(resourceKey, stream); } catch (ResourceException e) { throw new IOException( "Failed to convert resource-key into byte-array key: " + e); } } else { stream.writeByte(0); SerializerHelper.getInstance().writeObject(attribute, stream); } } } else if (SerializerHelper.getInstance().isSerializable(attribute)) { stream.writeByte(0); SerializerHelper.getInstance().writeObject(attribute, stream); } else { stream.writeByte(1); } } else if (attribute instanceof String) { stream.writeByte(0); SerializerHelper.getInstance().writeObject(attribute, stream); } else { stream.writeByte(1); } } } }
From source file:org.protempa.proposition.TemporalProposition.java
/** * Called while serializing a temporal proposition. It optimizes for when * the temporal proposition's interval is a {@link SimpleInterval}. * //from w w w.ja v a2s .co m * @param s * an {@link ObjectOutputStream}. * @throws IOException * when an error occurs during serialization. */ protected void writeTemporalProposition(ObjectOutputStream s) throws IOException { if (this.interval instanceof SimpleInterval) { long start = this.interval.getMinStart(); long finish = this.interval.getMinFinish(); Granularity startGran = this.interval.getStartGranularity(); Granularity finishGran = this.interval.getFinishGranularity(); if (start == finish && startGran == finishGran) { s.writeChar(0); s.writeLong(start); s.writeObject(startGran); } else { s.writeChar(1); s.writeLong(start); s.writeObject(startGran); s.writeLong(finish); s.writeObject(finishGran); } } else { s.writeChar(2); s.writeObject(this.interval.getMinStart()); s.writeObject(this.interval.getMaxStart()); s.writeObject(this.interval.getStartGranularity()); s.writeObject(this.interval.getMinFinish()); s.writeObject(this.interval.getMaxFinish()); s.writeObject(this.interval.getFinishGranularity()); } }
From source file:org.sventon.cache.direntrycache.CompassDirEntryCache.java
/** * @throws CacheException if unable to save revision number. *///from ww w.j av a2s . com private void saveLatestRevisionNumber() throws CacheException { logger.info("Saving file to disk, " + latestCachedRevisionFile); ObjectOutputStream out = null; try { out = new ObjectOutputStream(new FileOutputStream(latestCachedRevisionFile)); out.writeLong(getLatestCachedRevisionNumber()); out.flush(); out.close(); } catch (IOException ioex) { throw new CacheException("Unable to store file to disk", ioex); } finally { IOUtils.closeQuietly(out); } }