mirror of
https://github.com/Qortal/qortal.git
synced 2025-05-05 17:27:52 +00:00
Fixed exception in readJson(), and removed some duplicated code.
This commit is contained in:
parent
dc25d33739
commit
10f12221c9
@ -2,6 +2,7 @@ package org.qortal.arbitrary.metadata;
|
|||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.json.JSONException;
|
||||||
import org.qortal.repository.DataException;
|
import org.qortal.repository.DataException;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
@ -34,7 +35,7 @@ public class ArbitraryDataMetadata {
|
|||||||
this.filePath = filePath;
|
this.filePath = filePath;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void readJson() throws DataException {
|
protected void readJson() throws DataException, JSONException {
|
||||||
// To be overridden
|
// To be overridden
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -44,8 +45,13 @@ public class ArbitraryDataMetadata {
|
|||||||
|
|
||||||
|
|
||||||
public void read() throws IOException, DataException {
|
public void read() throws IOException, DataException {
|
||||||
this.loadJson();
|
try {
|
||||||
this.readJson();
|
this.loadJson();
|
||||||
|
this.readJson();
|
||||||
|
|
||||||
|
} catch (JSONException e) {
|
||||||
|
throw new DataException(String.format("Unable to read JSON: %s", e.getMessage()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void write() throws IOException, DataException {
|
public void write() throws IOException, DataException {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package org.qortal.arbitrary.metadata;
|
package org.qortal.arbitrary.metadata;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.qortal.repository.DataException;
|
import org.qortal.repository.DataException;
|
||||||
import org.qortal.utils.Base58;
|
import org.qortal.utils.Base58;
|
||||||
@ -22,7 +23,7 @@ public class ArbitraryDataMetadataCache extends ArbitraryDataQortalMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void readJson() throws DataException {
|
protected void readJson() throws DataException, JSONException {
|
||||||
if (this.jsonString == null) {
|
if (this.jsonString == null) {
|
||||||
throw new DataException("Patch JSON string is null");
|
throw new DataException("Patch JSON string is null");
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ package org.qortal.arbitrary.metadata;
|
|||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.qortal.arbitrary.ArbitraryDataDiff.*;
|
import org.qortal.arbitrary.ArbitraryDataDiff.*;
|
||||||
import org.qortal.repository.DataException;
|
import org.qortal.repository.DataException;
|
||||||
@ -40,7 +41,7 @@ public class ArbitraryDataMetadataPatch extends ArbitraryDataQortalMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void readJson() throws DataException {
|
protected void readJson() throws DataException, JSONException {
|
||||||
if (this.jsonString == null) {
|
if (this.jsonString == null) {
|
||||||
throw new DataException("Patch JSON string is null");
|
throw new DataException("Patch JSON string is null");
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package org.qortal.arbitrary.metadata;
|
|||||||
|
|
||||||
import org.apache.logging.log4j.LogManager;
|
import org.apache.logging.log4j.LogManager;
|
||||||
import org.apache.logging.log4j.Logger;
|
import org.apache.logging.log4j.Logger;
|
||||||
|
import org.json.JSONException;
|
||||||
import org.qortal.repository.DataException;
|
import org.qortal.repository.DataException;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
@ -46,20 +47,6 @@ public class ArbitraryDataQortalMetadata extends ArbitraryDataMetadata {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void readJson() throws DataException {
|
|
||||||
// To be overridden
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void buildJson() {
|
|
||||||
// To be overridden
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void read() throws IOException, DataException {
|
|
||||||
this.loadJson();
|
|
||||||
this.readJson();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void write() throws IOException, DataException {
|
public void write() throws IOException, DataException {
|
||||||
@ -94,9 +81,4 @@ public class ArbitraryDataQortalMetadata extends ArbitraryDataMetadata {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getJsonString() {
|
|
||||||
return this.jsonString;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package org.qortal.arbitrary.metadata;
|
package org.qortal.arbitrary.metadata;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.qortal.arbitrary.misc.Category;
|
import org.qortal.arbitrary.misc.Category;
|
||||||
import org.qortal.repository.DataException;
|
import org.qortal.repository.DataException;
|
||||||
@ -33,7 +34,7 @@ public class ArbitraryDataTransactionMetadata extends ArbitraryDataMetadata {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void readJson() throws DataException {
|
protected void readJson() throws DataException, JSONException {
|
||||||
if (this.jsonString == null) {
|
if (this.jsonString == null) {
|
||||||
throw new DataException("Transaction metadata JSON string is null");
|
throw new DataException("Transaction metadata JSON string is null");
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user