/** * compare the byte-array representation of two TaskObjects. * * @param f TaskObject * @param s TaskObject * @return true if the two arguments have the same byte-array */ private boolean sameBytes(TaskObject f, TaskObject s) { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ObjectOutput out = null; try { out = new ObjectOutputStream(bos); out.writeObject(f); byte[] fs = bos.toByteArray(); out.writeObject(s); byte[] ss = bos.toByteArray(); if (fs.length != ss.length) return false; for (int i = 0; i < fs.length; i++) { if (fs[i] != ss[i]) return false; } return true; } catch (IOException e) { e.printStackTrace(); return false; } finally { if (out != null) { try { out.close(); } catch (IOException e) { // ignore } try { bos.close(); } catch (IOException e) { // ignore } } } }
/** * @param out Output stream. * @param err Error cause. */ private void sendErrorResponse(ObjectOutput out, Exception err) { try { out.writeObject(new IpcSharedMemoryInitResponse(err)); } catch (IOException e) { U.error(log, "Failed to send error response to client.", e); } }