use of org.apache.pulsar.functions.worker.dlog.DLOutputStream in project incubator-pulsar by apache.
the class Utils method uploadToBookeeper.
public static void uploadToBookeeper(Namespace dlogNamespace, InputStream uploadedInputStream, String destPkgPath) throws IOException {
// if the dest directory does not exist, create it.
if (dlogNamespace.logExists(destPkgPath)) {
// if the destination file exists, write a log message
log.info(String.format("Target function file already exists at '%s'. Overwriting it now", destPkgPath));
dlogNamespace.deleteLog(destPkgPath);
}
// copy the topology package to target working directory
log.info(String.format("Uploading function package to '%s'", destPkgPath));
try (DistributedLogManager dlm = dlogNamespace.openLog(destPkgPath)) {
try (AppendOnlyStreamWriter writer = dlm.getAppendOnlyStreamWriter()) {
try (OutputStream out = new DLOutputStream(dlm, writer)) {
int read = 0;
byte[] bytes = new byte[1024];
while ((read = uploadedInputStream.read(bytes)) != -1) {
out.write(bytes, 0, read);
}
out.flush();
}
}
}
}
Aggregations