
com.marklogic.developer.corb.PostBatchUpdateJsonFileTask Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of marklogic-corb Show documentation
Show all versions of marklogic-corb Show documentation
CoRB is a Java tool designed for bulk content-reprocessing of documents stored in MarkLogic.
package com.marklogic.developer.corb;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import static com.marklogic.developer.corb.Options.EXPORT_FILE_BOTTOM_CONTENT;
import static com.marklogic.developer.corb.util.StringUtils.isNotEmpty;
import static com.marklogic.developer.corb.util.StringUtils.trimToEmpty;
public class PostBatchUpdateJsonFileTask extends PostBatchUpdateFileTask {
private static final Object SYNC_OBJ = new Object();
private static final int COMMA = ',';
private static final int LINE_FEED = '\n';
@Override
protected void writeBottomContent() throws IOException {
String bottomContent = getProperty(EXPORT_FILE_BOTTOM_CONTENT);
String trimmedContent = trimToEmpty(bottomContent);
if (isNotEmpty(trimmedContent)) {
File exportFile = getExportFile();
try (RandomAccessFile f = new RandomAccessFile(exportFile, "rw")) {
long length = f.length() -1;
byte b;
do {
length -= 1;
f.seek(length);
b = f.readByte();
} while(b != COMMA && b != LINE_FEED && length > 0);
//If we hit the comma before the EOL
if (b == COMMA) {
f.setLength(length);
f.write(NEWLINE);
} else {
f.seek(f.length());
}
f.write(bottomContent.getBytes());
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy