Support altered data format
This commit is contained in:
parent
816d52b9b3
commit
2dc6170933
|
@ -61,8 +61,9 @@ public abstract class AbstractDatabase<T extends AbstractDatabaseDataSlice<V>, V
|
||||||
try (InputStream is = Utils.getContext().getAssets().open(fileName);
|
try (InputStream is = Utils.getContext().getAssets().open(fileName);
|
||||||
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is))) {
|
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(is))) {
|
||||||
|
|
||||||
if (!"MDI".equals(bufferedReader.readLine())) {
|
String headerString = bufferedReader.readLine();
|
||||||
LOG.debug("loadInfoData() incorrect header");
|
if (!"YACBSIAI".equals(headerString) && !"MDI".equals(headerString)) {
|
||||||
|
LOG.debug("loadInfoData() incorrect header: {}", headerString);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -126,7 +126,7 @@ public abstract class AbstractDatabaseDataSlice<T> {
|
||||||
|
|
||||||
LOG.trace("loadFromStream() reading endmark");
|
LOG.trace("loadFromStream() reading endmark");
|
||||||
String endmarkString = stream.readUtf8StringChars(6);
|
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);
|
throw new IllegalStateException("Endmark not found. Found instead: " + endmarkString);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -168,7 +168,7 @@ public class CommunityDatabase extends AbstractDatabase<CommunityDatabaseDataSli
|
||||||
|
|
||||||
private String getSecondarySliceFilePath(int id) {
|
private String getSecondarySliceFilePath(int id) {
|
||||||
File dir = Utils.getContext().getFilesDir();
|
File dir = Utils.getContext().getFilesDir();
|
||||||
return dir.getAbsolutePath() + "/sia_updates_" + id + ".mtz";
|
return dir.getAbsolutePath() + "/sia_updates_" + id + ".sia";
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetSecondaryDatabase() {
|
public void resetSecondaryDatabase() {
|
||||||
|
@ -177,7 +177,7 @@ public class CommunityDatabase extends AbstractDatabase<CommunityDatabaseDataSli
|
||||||
FileFilter fileFilter = new FileFilter() {
|
FileFilter fileFilter = new FileFilter() {
|
||||||
@Override
|
@Override
|
||||||
public boolean accept(File pathname) {
|
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())) {
|
if (contentType != null && "application".equals(contentType.type())) {
|
||||||
LOG.trace("updateSecondaryDbInternal() saving response data to file");
|
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;
|
int totalRead = 0;
|
||||||
try (InputStream in = body.byteStream();
|
try (InputStream in = body.byteStream();
|
||||||
|
|
|
@ -93,7 +93,8 @@ public class CommunityDatabaseDataSlice extends AbstractDatabaseDataSlice<Commun
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void loadFromStreamCheckHeader(String header) {
|
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);
|
throw new IllegalStateException("Invalid header. Actual value: " + header);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -169,7 +170,7 @@ public class CommunityDatabaseDataSlice extends AbstractDatabaseDataSlice<Commun
|
||||||
}
|
}
|
||||||
|
|
||||||
LittleEndianDataOutputStream stream = new LittleEndianDataOutputStream(outputStream);
|
LittleEndianDataOutputStream stream = new LittleEndianDataOutputStream(outputStream);
|
||||||
stream.writeUtf8StringChars("MTZF");
|
stream.writeUtf8StringChars("YABF");
|
||||||
stream.writeByte((byte) 1);
|
stream.writeByte((byte) 1);
|
||||||
stream.writeInt(newSlice != null ? newSlice.dbVersion : this.dbVersion);
|
stream.writeInt(newSlice != null ? newSlice.dbVersion : this.dbVersion);
|
||||||
stream.writeUtf8StringChars("ww");
|
stream.writeUtf8StringChars("ww");
|
||||||
|
@ -232,7 +233,7 @@ public class CommunityDatabaseDataSlice extends AbstractDatabaseDataSlice<Commun
|
||||||
}
|
}
|
||||||
stream.writeUtf8StringChars("CP");
|
stream.writeUtf8StringChars("CP");
|
||||||
stream.writeInt(0);
|
stream.writeInt(0);
|
||||||
stream.writeUtf8StringChars("MTZEND");
|
stream.writeUtf8StringChars("YABEND");
|
||||||
return true;
|
return true;
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
LOG.error("writeMerged()", e);
|
LOG.error("writeMerged()", e);
|
||||||
|
|
|
@ -8,7 +8,7 @@ class DatabaseDataSliceNode {
|
||||||
this.sliceTree = new DatabaseDataSliceNode[10];
|
this.sliceTree = new DatabaseDataSliceNode[10];
|
||||||
|
|
||||||
for (int i = 0; i <= 9; i++) {
|
for (int i = 0; i <= 9; i++) {
|
||||||
if (data.charAt(offset) == '+') {
|
if (data.charAt(offset) == '*' || data.charAt(offset) == '+') {
|
||||||
offset++;
|
offset++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,7 +15,7 @@ public class FeaturedDatabaseDataSlice extends AbstractDatabaseDataSlice<Feature
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void loadFromStreamCheckHeader(String header) {
|
protected void loadFromStreamCheckHeader(String header) {
|
||||||
if (!"MTZX".equalsIgnoreCase(header)) {
|
if (!"YABX".equalsIgnoreCase(header) && !"MTZX".equalsIgnoreCase(header)) {
|
||||||
throw new IllegalStateException("Invalid header. Actual value: " + header);
|
throw new IllegalStateException("Invalid header. Actual value: " + header);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue