Example usage for java.io ObjectOutputStream writeInt

List of usage examples for java.io ObjectOutputStream writeInt

Introduction

In this page you can find the example usage for java.io ObjectOutputStream writeInt.

Prototype

public void writeInt(int val) throws IOException 

Source Link

Document

Writes a 32 bit int.

Usage

From source file:org.eclipse.ecr.runtime.api.ServiceHost.java

private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();/*from   w  ww  . ja v  a2s . c o  m*/
    if (groups != null) {
        out.writeInt(groups.length);
        for (ServiceGroup group : groups) {
            out.writeObject(group.getName());
        }
    } else {
        out.writeInt(0);
    }
}

From source file:xbird.engine.remote.ExchangingRemoteFocusProxy.java

public byte[] fetchBytes(int size, boolean compress) throws RemoteException {
    if (size < 1) {
        throw new IllegalArgumentException("Illegal fetch size: " + size);
    }//from  w  w w .ja v a  2 s. com
    final Item[] result = new Item[size];
    int actsize = 0;
    while (actsize < size) {
        final Item e;
        try {
            e = _queue.take();
        } catch (InterruptedException ie) {
            throw new RemoteException(ie.getMessage(), ie);
        }
        if (e == SENTINEL) {
            break;
        }
        result[actsize++] = e;
    }
    final FastMultiByteArrayOutputStream bos = new FastMultiByteArrayOutputStream();
    final OutputStream os = compress ? new LZFOutputStream(bos) : bos;
    final ObjectOutputStream oos;
    try {
        oos = new ObjectOutputStream(os);
        oos.writeInt(actsize);
        for (int i = 0; i < actsize; i++) {
            oos.writeObject(result[i]);
            result[i] = null;
        }
        oos.flush();
    } catch (IOException e) {
        throw new RemoteException("failed to serialize", e);
    }
    final byte[] ary = bos.toByteArray_clear();
    try {
        oos.close();
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return ary;
}

From source file:org.review_board.ereviewboard.core.ReviewboardClientManager.java

void writeCache() {

    ObjectOutputStream out = null;
    try {//ww  w. j  a v  a2s .co  m
        out = new ObjectOutputStream(new FileOutputStream(cacheFile));

        out.writeInt(dataByUrl.size());
        for (Entry<String, ReviewboardClientData> entry : dataByUrl.entrySet()) {
            out.writeObject(entry.getKey());
            out.writeObject(entry.getValue());
        }

        out.flush();
    } catch (IOException e) {
        logWarning("The Reviewboard respository data cache could not be written", e);
    } catch (RuntimeException e) {
        logWarning("The Reviewboard respository data cache could not be written", e);
    } finally {
        IOUtils.closeQuietly(out);
    }
}

From source file:org.photovault.replication.ChangeDTO.java

/**
 Write the description of actual change operations to a stream.
 @param os//from ww w.j av  a 2s .  com
 @throws java.io.IOException
 */
private void writeChange(ObjectOutputStream os) throws IOException {
    os.writeInt(changedFields.size());
    for (Map.Entry<String, FieldChange> e : changedFields.entrySet()) {
        os.writeObject(e.getValue());
    }
}

From source file:net.sf.webissues.core.WebIssuesClientManager.java

public void writeCache() {
    if (cacheFile == null) {
        return;/*  w  w w  .  ja  v a 2  s .c  o  m*/
    }

    ObjectOutputStream out = null;
    try {
        out = new ObjectOutputStream(new FileOutputStream(cacheFile));
        out.writeInt(clientByUrl.size());
        for (String url : clientByUrl.keySet()) {
            out.writeObject(url);
            out.writeObject(clientByUrl.get(url));
        }
    } catch (IOException e) {
        e.printStackTrace();
        StatusHandler.log(new Status(IStatus.WARNING, WebIssuesCorePlugin.ID_PLUGIN,
                "The WebIssues respository configuration cache could not be written", e));
    } finally {
        if (out != null) {
            try {
                out.close();
            } catch (IOException e) {
                // ignore
            }
        }
    }
}

From source file:com.kynetx.api.java

protected void storeCookies(CookieStore toStore) throws IOException {
    if (isWritable()) {
        File path = new File(context.getExternalFilesDir(null), "cookies");

        OutputStream output = new FileOutputStream(path);
        ObjectOutputStream oos = new ObjectOutputStream(output);

        List<Cookie> cookies = toStore.getCookies();

        oos.writeInt(cookies.size());

        for (int i = 0; i < cookies.size(); i++) {
            Cookie cookie = cookies.get(i);
            oos.writeObject(cookie.getName());
            oos.writeObject(cookie.getValue());
            oos.writeObject(cookie.getDomain());
            oos.writeObject(cookie.getPath());
            oos.writeInt(cookie.getVersion());
        }/*from   w ww.  j a v  a  2  s.  c  om*/

        oos.close();
    } else {
        throw new IOException();
    }
}

From source file:jopt.csp.util.SortableIntList.java

private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();/*from w  w  w . jav  a  2 s .c  o m*/
    out.writeInt(data.length);
    for (int i = 0; i < size; i++) {
        out.writeInt(data[i]);
    }
}

From source file:xbird.engine.remote.RemoteFocusProxy.java

public byte[] fetchBytes(int size, boolean compress) throws RemoteException {
    if (size < 1) {
        throw new IllegalArgumentException("Illegal fetch size: " + size);
    }//from w  w w  . j a  v a  2s  .c om
    final Item[] result = new Item[size];
    final IFocus<Item> delegate = _delegate;
    int actsize = 0;
    while (actsize < size) {
        if (!delegate.hasNext()) {
            break;
        }
        result[actsize++] = delegate.next();
    }
    final FastMultiByteArrayOutputStream bos = new FastMultiByteArrayOutputStream();
    final OutputStream os = compress ? new LZFOutputStream(bos) : bos;
    final ObjectOutputStream oos;
    try {
        oos = new ObjectOutputStream(os);
        oos.writeInt(actsize);
        for (int i = 0; i < actsize; i++) {
            oos.writeObject(result[i]);
            result[i] = null;
        }
        oos.flush();
    } catch (IOException e) {
        throw new RemoteException("failed to serialize", e);
    }
    final byte[] ary = bos.toByteArray_clear();
    try {
        oos.close();
    } catch (IOException e) {
        throw new IllegalStateException(e);
    }
    return ary;
}

From source file:BooleanArrayList.java

private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();/*from  w  w  w.ja  v  a 2s.  c om*/
    out.writeInt(array.length);
    for (int i = 0; i < size; i++) {
        out.writeBoolean(array[i]);
    }
}

From source file:DoubleArrayList.java

private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();//from  www  .j a v a2  s  . co m
    out.writeInt(array.length);
    for (int i = 0; i < size; i++) {
        out.writeDouble(array[i]);
    }
}