Use the IndexZipper to zip files when uploading
This commit is contained in:
parent
f55cef6237
commit
d84c78ddac
2 changed files with 12 additions and 26 deletions
|
@ -26,8 +26,6 @@ import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.zip.ZipEntry;
|
|
||||||
import java.util.zip.ZipOutputStream;
|
|
||||||
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
import javax.xml.parsers.DocumentBuilderFactory;
|
||||||
import javax.xml.parsers.ParserConfigurationException;
|
import javax.xml.parsers.ParserConfigurationException;
|
||||||
|
@ -37,6 +35,7 @@ import net.osmand.LogUtil;
|
||||||
import net.osmand.binary.BinaryMapIndexReader;
|
import net.osmand.binary.BinaryMapIndexReader;
|
||||||
import net.osmand.data.IndexConstants;
|
import net.osmand.data.IndexConstants;
|
||||||
import net.osmand.data.index.ExtractGooglecodeAuthorization.GooglecodeUploadTokens;
|
import net.osmand.data.index.ExtractGooglecodeAuthorization.GooglecodeUploadTokens;
|
||||||
|
import net.osmand.data.index.IndexZipper.OneFileException;
|
||||||
import net.osmand.data.preparation.DBDialect;
|
import net.osmand.data.preparation.DBDialect;
|
||||||
import net.osmand.data.preparation.IndexCreator;
|
import net.osmand.data.preparation.IndexCreator;
|
||||||
import net.osmand.data.preparation.MapZooms;
|
import net.osmand.data.preparation.MapZooms;
|
||||||
|
@ -59,7 +58,6 @@ public class IndexBatchCreator {
|
||||||
|
|
||||||
protected static final Log log = LogUtil.getLog(IndexBatchCreator.class);
|
protected static final Log log = LogUtil.getLog(IndexBatchCreator.class);
|
||||||
private final static double MIN_SIZE_TO_UPLOAD = 0.015d;
|
private final static double MIN_SIZE_TO_UPLOAD = 0.015d;
|
||||||
private final static double MIN_SIZE_TO_NOT_ZIP = 2d;
|
|
||||||
private final static double MAX_SIZE_TO_NOT_SPLIT = 190d;
|
private final static double MAX_SIZE_TO_NOT_SPLIT = 190d;
|
||||||
private final static double MAX_UPLOAD_SIZE = 195d;
|
private final static double MAX_UPLOAD_SIZE = 195d;
|
||||||
|
|
||||||
|
@ -640,42 +638,30 @@ public class IndexBatchCreator {
|
||||||
// do not upload small files
|
// do not upload small files
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String regionName = fileName.substring(0, fileName.lastIndexOf('_', fileName.indexOf('.')));
|
||||||
|
summary += regionName;
|
||||||
|
summary = summary.replace('_', ' ');
|
||||||
|
|
||||||
File toUpload = f;
|
File toUpload = f;
|
||||||
if(mbLengh > MIN_SIZE_TO_NOT_ZIP && (fileName.endsWith(".odb") || fileName.endsWith(".obf")) && zip){
|
if((fileName.endsWith(".odb") || fileName.endsWith(".obf")) && zip){
|
||||||
String n = fileName;
|
String n = fileName;
|
||||||
if(fileName.endsWith(".odb")){
|
if(fileName.endsWith(".odb")){
|
||||||
n = fileName.substring(0, fileName.length() - 4);
|
n = fileName.substring(0, fileName.length() - 4);
|
||||||
}
|
}
|
||||||
String zipFileName = n+".zip";
|
String zipFileName = n+".zip";
|
||||||
File zFile = new File(f.getParentFile(), zipFileName);
|
|
||||||
log.info("Zipping file " + fileName);
|
log.info("Zipping file " + fileName);
|
||||||
try {
|
try {
|
||||||
ZipOutputStream zout = new ZipOutputStream(new FileOutputStream(zFile));
|
toUpload = IndexZipper.zip(f, zipFileName, summary);
|
||||||
zout.setLevel(9);
|
} catch (OneFileException e) {
|
||||||
ZipEntry zEntry = new ZipEntry(fileName);
|
|
||||||
zEntry.setSize(f.length());
|
|
||||||
zout.putNextEntry(zEntry);
|
|
||||||
FileInputStream is = new FileInputStream(f);
|
|
||||||
byte[] BUFFER = new byte[8192];
|
|
||||||
int read = 0;
|
|
||||||
while((read = is.read(BUFFER)) != -1){
|
|
||||||
zout.write(BUFFER, 0, read);
|
|
||||||
}
|
|
||||||
is.close();
|
|
||||||
zout.close();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error("Exception while zipping file", e);
|
log.error("Exception while zipping file", e);
|
||||||
|
return ; //do not continue if error
|
||||||
}
|
}
|
||||||
if(f.delete()){
|
if(f.delete()){
|
||||||
log.info("Source odb file was deleted");
|
log.info("Source odb file was deleted");
|
||||||
}
|
}
|
||||||
toUpload = zFile;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String regionName = fileName.substring(0, fileName.lastIndexOf('_', fileName.indexOf('.')));
|
|
||||||
summary += regionName;
|
|
||||||
summary = summary.replace('_', ' ');
|
|
||||||
|
|
||||||
List<File> splittedFiles = Collections.emptyList();
|
List<File> splittedFiles = Collections.emptyList();
|
||||||
try {
|
try {
|
||||||
splittedFiles = splitFiles(toUpload);
|
splittedFiles = splitFiles(toUpload);
|
||||||
|
|
|
@ -82,7 +82,7 @@ public class IndexZipper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private File zip(File f, String zipFileName, String description)
|
public static File zip(File f, String zipFileName, String description)
|
||||||
throws OneFileException {
|
throws OneFileException {
|
||||||
File zFile = new File(f.getParentFile(), zipFileName);
|
File zFile = new File(f.getParentFile(), zipFileName);
|
||||||
try {
|
try {
|
||||||
|
@ -189,7 +189,7 @@ public class IndexZipper {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void copyAndClose(InputStream in, OutputStream out)
|
public static void copyAndClose(InputStream in, OutputStream out)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
Algoritms.streamCopy(in, out);
|
Algoritms.streamCopy(in, out);
|
||||||
Algoritms.closeStream(in);
|
Algoritms.closeStream(in);
|
||||||
|
|
Loading…
Reference in a new issue