Skip to content

Commit

Permalink
make the writeEvent methods return a boolean just like the classes th…
Browse files Browse the repository at this point in the history
…at write evio version 6
  • Loading branch information
carltimmer committed Apr 24, 2024
1 parent 065af45 commit d45dcd9
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 49 deletions.
76 changes: 52 additions & 24 deletions java/org/jlab/coda/jevio/EventWriterUnsyncV4.java
Original file line number Diff line number Diff line change
Expand Up @@ -2930,19 +2930,23 @@ public boolean hasRoom(int bytes) {
*
* @param node object representing the event to write in buffer form
* @param force if writing to disk, force it to write event to the disk.
*
* @return if writing to buffer: true if event was added to record, false if buffer full,
* or bank and bankBuffer args are both null.
* If there is an InterruptedException.
*
* @throws IOException if error writing file
* @throws EvioException if event is opposite byte order of internal buffer;
* if close() already called;
* if bad eventBuffer format;
* if file could not be opened for writing;
* if file exists but user requested no over-writing;
* if no room when writing to user-given buffer;
*/
public void writeEvent(EvioNode node, boolean force)
public boolean writeEvent(EvioNode node, boolean force)
throws EvioException, IOException {

// Duplicate buffer so we can set pos & limit without messing others up
writeEvent(node, force, true);
return writeEvent(node, force, true);
}

/**
Expand All @@ -2955,16 +2959,20 @@ public void writeEvent(EvioNode node, boolean force)
* @param force if writing to disk, force it to write event to the disk.
* @param duplicate if true, duplicate node's buffer so its position and limit
* can be changed without issue.
*
* @return if writing to buffer: true if event was added to record, false if buffer full,
* or bank and bankBuffer args are both null.
* If there is an InterruptedException.
*
* @throws IOException if error writing file
* @throws EvioException if event is opposite byte order of internal buffer;
* if close() already called;
* if bad eventBuffer format;
* if file could not be opened for writing;
* if file exists but user requested no over-writing;
* if no room when writing to user-given buffer;
* if null node arg;
*/
public void writeEvent(EvioNode node, boolean force, boolean duplicate)
public boolean writeEvent(EvioNode node, boolean force, boolean duplicate)
throws EvioException, IOException {

if (node == null) {
Expand All @@ -2987,7 +2995,7 @@ public void writeEvent(EvioNode node, boolean force, boolean duplicate)

int pos = node.getPosition();
eventBuffer.limit(pos + node.getTotalBytes()).position(pos);
writeEvent(null, eventBuffer, force);
return writeEvent(null, eventBuffer, force);

// Shouldn't the pos & lim be reset for non-duplicate?
// It don't think it matters since node knows where to
Expand Down Expand Up @@ -3079,17 +3087,21 @@ public boolean writeEventToFile(EvioNode node, boolean force, boolean duplicate)
* close, flush, setFirstEvent, or getByteBuffer.
*
* @param eventBuffer the event (bank) to write in buffer form
*
* @return if writing to buffer: true if event was added to record, false if buffer full,
* or bank and bankBuffer args are both null.
* If there is an InterruptedException.
*
* @throws IOException if error writing file
* @throws EvioException if event is opposite byte order of internal buffer;
* if close() already called;
* if bad eventBuffer format;
* if file could not be opened for writing;
* if file exists but user requested no over-writing;
* if no room when writing to user-given buffer;
*/
public void writeEvent(ByteBuffer eventBuffer)
public boolean writeEvent(ByteBuffer eventBuffer)
throws EvioException, IOException {
writeEvent(null, eventBuffer, false);
return writeEvent(null, eventBuffer, false);
}

/**
Expand All @@ -3102,15 +3114,19 @@ public void writeEvent(ByteBuffer eventBuffer)
* close, flush, setFirstEvent, or getByteBuffer.
*
* @param bank the bank to write.
*
* @return if writing to buffer: true if event was added to record, false if buffer full,
* or bank and bankBuffer args are both null.
* If there is an InterruptedException.
*
* @throws IOException if error writing file
* @throws EvioException if close() already called;
* if file could not be opened for writing;
* if file exists but user requested no over-writing;
* if no room when writing to user-given buffer;
*/
public void writeEvent(EvioBank bank)
public boolean writeEvent(EvioBank bank)
throws EvioException, IOException {
writeEvent(bank, null, false);
return writeEvent(bank, null, false);
}


Expand All @@ -3128,17 +3144,20 @@ public void writeEvent(EvioBank bank)
* @param bankBuffer the bank (as a ByteBuffer object) to write.
* @param force if writing to disk, force it to write event to the disk.
*
* @return if writing to buffer: true if event was added to record, false if buffer full,
* or bank and bankBuffer args are both null.
* If there is an InterruptedException.
*
* @throws IOException if error writing file
* @throws EvioException if event is opposite byte order of internal buffer;
* if close() already called;
* if bad eventBuffer format;
* if file could not be opened for writing;
* if file exists but user requested no over-writing;
* if no room when writing to user-given buffer;
*/
public void writeEvent(ByteBuffer bankBuffer, boolean force)
public boolean writeEvent(ByteBuffer bankBuffer, boolean force)
throws EvioException, IOException {
writeEvent(null, bankBuffer, force);
return writeEvent(null, bankBuffer, force);
}


Expand All @@ -3156,15 +3175,18 @@ public void writeEvent(ByteBuffer bankBuffer, boolean force)
* @param bank the bank to write.
* @param force if writing to disk, force it to write event to the disk.
*
* @return if writing to buffer: true if event was added to record, false if buffer full,
* or bank and bankBuffer args are both null.
* If there is an InterruptedException.
*
* @throws IOException if error writing file
* @throws EvioException if close() already called;
* if file could not be opened for writing;
* if file exists but user requested no over-writing;
* if no room when writing to user-given buffer;
*/
public void writeEvent(EvioBank bank, boolean force)
public boolean writeEvent(EvioBank bank, boolean force)
throws EvioException, IOException {
writeEvent(bank, null, force);
return writeEvent(bank, null, force);
}


Expand All @@ -3188,15 +3210,19 @@ public void writeEvent(EvioBank bank, boolean force)
* @param bankBuffer the bank (as a ByteBuffer object) to write.
* @param force if writing to disk, force it to write event to the disk.
*
* @return if writing to buffer: true if event was added to record, false if buffer full,
* or bank and bankBuffer args are both null.
* If there is an InterruptedException.
*
* @throws IOException if error writing file
* @throws EvioException if event is opposite byte order of internal buffer;
* if bad bankBuffer format;
* if close() already called;
* if file could not be opened for writing;
* if file exists but user requested no over-writing;
* if no room when writing to user-given buffer;
*/
private void writeEvent(EvioBank bank, ByteBuffer bankBuffer, boolean force)
private boolean writeEvent(EvioBank bank, ByteBuffer bankBuffer,
boolean force)
throws EvioException, IOException {

if (closed) {
Expand Down Expand Up @@ -3240,7 +3266,7 @@ else if (bank != null) {
currentEventBytes = bank.getTotalBytes();
}
else {
return;
return false;
}

// if (split > 0) {
Expand Down Expand Up @@ -3346,7 +3372,7 @@ else if ((!writeNewBlockHeader && ((bufferSize - bytesWrittenToBuffer) < current
( writeNewBlockHeader && ((bufferSize - bytesWrittenToBuffer) < currentEventBytes + 2*headerBytes))) {

if (!toFile) {
throw new EvioException("Buffer too small to write event");
return false;
}

// if (debug) {
Expand Down Expand Up @@ -3391,7 +3417,7 @@ else if ((!writeNewBlockHeader && ((bufferSize - bytesWrittenToBuffer) < current
flushToFile(false, false);
}
catch (InterruptedException e) {
return;
return false;
}
catch (ExecutionException e) {
throw new IOException(e);
Expand Down Expand Up @@ -3481,7 +3507,7 @@ else if ((!writeNewBlockHeader && ((bufferSize - bytesWrittenToBuffer) < current
flushToFile(true, false);
}
catch (InterruptedException e) {
return;
return false;
}
catch (ExecutionException e) {
throw new IOException(e);
Expand All @@ -3490,6 +3516,8 @@ else if ((!writeNewBlockHeader && ((bufferSize - bytesWrittenToBuffer) < current
// Start a new block
resetBuffer(false);
}

return true;
}


Expand Down
Loading

0 comments on commit d45dcd9

Please sign in to comment.