Hi,
I am exporting all the documents from a collection to local directory .
Below is my code.
public class Extract {
static // replace with your MarkLogic Server connection information
DatabaseClient client =
DatabaseClientFactory.newClient("x", x,
"x", "x",
Authentication.DIGEST);
private static String EX_DIR = "F:/JavaExtract";
// Loading files into the database asynchronously
public static void exportByQuery() {
DataMovementManager dmm = client.newDataMovementManager();
// Construct a directory query with which to drive the job.
QueryManager qm = client.newQueryManager();
StringQueryDefinition query = qm.newStringDefinition();
query.setCollections("GOT");
// Create and configure the batcher
QueryBatcher batcher = dmm.newQueryBatcher(query);
batcher.withBatchSize(10)
.withThreadCount(1)
.onUrisReady(
new ExportListener()
.onDocumentReady(doc-> {
String uriParts[] = doc.getUri().split("/");
try {
FileOutputStream dest = new
FileOutputStream("F:/Json/file.zip");
ZipOutputStream out = new
ZipOutputStream(new
BufferedOutputStream(dest));
ZipEntry e = new
ZipEntry(uriParts[uriParts.length - 1]);
out.putNextEntry(e);
byte[] data = doc.getContent(
new StringHandle()).toBuffer();
doc.getFormat();
out.write(data, 0, data.length);
out.closeEntry();
out.close();
} catch (Exception e) {
e.printStackTrace();
}
}))
.onQueryFailure( exception ->
exception.printStackTrace() );
dmm.startJob(batcher);
// Wait for the job to complete, and then stop it.
batcher.awaitCompletion();
dmm.stopJob(batcher);
}
public static void main(String[] args) {
exportByQuery();
}
}
When i am running it is taking only the last document in `GOT` collection
and keeping in zip rather than taking all.
Cant figure it out where it where i am doing wrong?
Any Help Is Appreciated
Thanks
_______________________________________________
General mailing list
[email protected]
Manage your subscription at:
http://developer.marklogic.com/mailman/listinfo/general