Support altered data format

This commit is contained in:
xynngh 2019-09-01 16:16:58 +04:00
parent 816d52b9b3
commit 2dc6170933
6 changed files with 13 additions and 11 deletions

View File

@ -61,8 +61,9 @@ public abstract class AbstractDatabase<T extends AbstractDatabaseDataSlice<V>, V
try (InputStream is = Utils.getContext().getAssets().open(fileName);
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is))) {
if (!"MDI".equals(bufferedReader.readLine())) {
LOG.debug("loadInfoData() incorrect header");
String headerString = bufferedReader.readLine();
if (!"YACBSIAI".equals(headerString) && !"MDI".equals(headerString)) {
LOG.debug("loadInfoData() incorrect header: {}", headerString);
return false;
}

View File

@ -126,7 +126,7 @@ public abstract class AbstractDatabaseDataSlice<T> {
LOG.trace("loadFromStream() reading endmark");
String endmarkString = stream.readUtf8StringChars(6);
if (!"MTZEND".equalsIgnoreCase(endmarkString)) {
if (!"YABEND".equalsIgnoreCase(endmarkString) && !"MTZEND".equalsIgnoreCase(endmarkString)) {
throw new IllegalStateException("Endmark not found. Found instead: " + endmarkString);
}

View File

@ -168,7 +168,7 @@ public class CommunityDatabase extends AbstractDatabase<CommunityDatabaseDataSli
private String getSecondarySliceFilePath(int id) {
File dir = Utils.getContext().getFilesDir();
return dir.getAbsolutePath() + "/sia_updates_" + id + ".mtz";
return dir.getAbsolutePath() + "/sia_updates_" + id + ".sia";
}
public void resetSecondaryDatabase() {
@ -177,7 +177,7 @@ public class CommunityDatabase extends AbstractDatabase<CommunityDatabaseDataSli
FileFilter fileFilter = new FileFilter() {
@Override
public boolean accept(File pathname) {
return pathname.getName().endsWith(".mtz");
return pathname.getName().endsWith(".sia");
}
};
@ -242,7 +242,7 @@ public class CommunityDatabase extends AbstractDatabase<CommunityDatabaseDataSli
if (contentType != null && "application".equals(contentType.type())) {
LOG.trace("updateSecondaryDbInternal() saving response data to file");
File tempFile = File.createTempFile("mtz", "database", Utils.getContext().getCacheDir());
File tempFile = File.createTempFile("sia", "database", Utils.getContext().getCacheDir());
int totalRead = 0;
try (InputStream in = body.byteStream();

View File

@ -93,7 +93,8 @@ public class CommunityDatabaseDataSlice extends AbstractDatabaseDataSlice<Commun
@Override
protected void loadFromStreamCheckHeader(String header) {
if (!"MTZF".equalsIgnoreCase(header) && !"MTZD".equalsIgnoreCase(header)) {
if (!"YABF".equalsIgnoreCase(header) && !"MTZF".equalsIgnoreCase(header)
&& !"MTZD".equalsIgnoreCase(header)) {
throw new IllegalStateException("Invalid header. Actual value: " + header);
}
}
@ -169,7 +170,7 @@ public class CommunityDatabaseDataSlice extends AbstractDatabaseDataSlice<Commun
}
LittleEndianDataOutputStream stream = new LittleEndianDataOutputStream(outputStream);
stream.writeUtf8StringChars("MTZF");
stream.writeUtf8StringChars("YABF");
stream.writeByte((byte) 1);
stream.writeInt(newSlice != null ? newSlice.dbVersion : this.dbVersion);
stream.writeUtf8StringChars("ww");
@ -232,7 +233,7 @@ public class CommunityDatabaseDataSlice extends AbstractDatabaseDataSlice<Commun
}
stream.writeUtf8StringChars("CP");
stream.writeInt(0);
stream.writeUtf8StringChars("MTZEND");
stream.writeUtf8StringChars("YABEND");
return true;
} catch (IOException e) {
LOG.error("writeMerged()", e);

View File

@ -8,7 +8,7 @@ class DatabaseDataSliceNode {
this.sliceTree = new DatabaseDataSliceNode[10];
for (int i = 0; i <= 9; i++) {
if (data.charAt(offset) == '+') {
if (data.charAt(offset) == '*' || data.charAt(offset) == '+') {
offset++;
continue;
}

View File

@ -15,7 +15,7 @@ public class FeaturedDatabaseDataSlice extends AbstractDatabaseDataSlice<Feature
@Override
protected void loadFromStreamCheckHeader(String header) {
if (!"MTZX".equalsIgnoreCase(header)) {
if (!"YABX".equalsIgnoreCase(header) && !"MTZX".equalsIgnoreCase(header)) {
throw new IllegalStateException("Invalid header. Actual value: " + header);
}
}