net.ravendb.embedded.ExtractFromJarServerProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ravendb-embedded Show documentation
Show all versions of ravendb-embedded Show documentation
RavenDB package for running RavenDB in embedded mode
package net.ravendb.embedded;
import org.apache.commons.io.IOUtils;
import java.io.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class ExtractFromJarServerProvider implements IProvideRavenDBServer {
@Override
public void provide(String targetDirectory) throws IOException {
InputStream resourceAsStream =
ExtractFromJarServerProvider.class.getResourceAsStream("/ravendb-server.zip");
if (resourceAsStream == null) {
throw new IllegalStateException("Unable to find resource: ravendb-server.zip");
}
unzip(resourceAsStream, targetDirectory);
}
public static void unzip(InputStream source, String out) throws IOException {
try (ZipInputStream zis = new ZipInputStream(source)) {
ZipEntry entry = zis.getNextEntry();
while (entry != null) {
File file = new File(out, entry.getName());
if (entry.isDirectory()) {
file.mkdirs();
} else {
File parent = file.getParentFile();
if (!parent.exists()) {
parent.mkdirs();
}
try (BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file))) {
IOUtils.copy(zis, bos);
}
}
entry = zis.getNextEntry();
}
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy