Skip to content

Commit

Permalink
Export: minor fix to setup compressionLevel and compressionBuffer
Browse files Browse the repository at this point in the history
  • Loading branch information
lvca committed Jul 15, 2014
1 parent 6c1e27a commit 4f2e4ee
Showing 1 changed file with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.zip.Deflater;
import java.util.zip.GZIPOutputStream;

/**
Expand All @@ -56,9 +57,11 @@
* @author Luca Garulli (l.garulli--at--orientechnologies.com)
*/
public class ODatabaseExport extends ODatabaseImpExpAbstract {
public static final int VERSION = 8;
public static final int VERSION = 8;
protected OJSONWriter writer;
protected long recordExported;
protected int compressionLevel = Deflater.BEST_SPEED;
protected int compressionBuffer = 16384; // 16Kb

public ODatabaseExport(final ODatabaseRecord iDatabase, final String iFileName, final OCommandOutputListener iListener)
throws IOException {
Expand All @@ -76,7 +79,13 @@ public ODatabaseExport(final ODatabaseRecord iDatabase, final String iFileName,
if (f.exists())
f.delete();

writer = new OJSONWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(fileName), 16384))); // 16KB
final GZIPOutputStream gzipOS = new GZIPOutputStream(new FileOutputStream(fileName), compressionBuffer) {
{
def.setLevel(compressionLevel);
}
};

writer = new OJSONWriter(new OutputStreamWriter(gzipOS));
writer.beginObject();
iDatabase.getLevel1Cache().setEnable(false);
iDatabase.getLevel2Cache().setEnable(false);
Expand Down Expand Up @@ -124,7 +133,7 @@ public ODatabaseExport exportDatabase() {

writer.flush();
} catch (Exception e) {
e.printStackTrace();
OLogManager.instance().error(this, "Error on exporting database '%s' to: %s", e, database.getName(), fileName);
throw new ODatabaseExportException("Error on exporting database '" + database.getName() + "' to: " + fileName, e);
} finally {
close();
Expand Down Expand Up @@ -249,6 +258,16 @@ protected int getMaxClusterId() {
return totalCluster;
}

@Override
protected void parseSetting(final String option, final List<String> items) {
if (option.equalsIgnoreCase("-compressionLevel"))
compressionLevel = Integer.parseInt(items.get(0));
else if (option.equalsIgnoreCase("-compressionBuffer"))
compressionBuffer = Integer.parseInt(items.get(0));
else
super.parseSetting(option, items);
}

private void exportClusters() throws IOException {
listener.onMessage("\nExporting clusters...");

Expand Down

0 comments on commit 4f2e4ee

Please sign in to comment.