mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 11:19:04 +01:00
Parser for structured metadata.
This commit is contained in:
48
briar-api/src/org/briarproject/api/data/BdfDictionary.java
Normal file
48
briar-api/src/org/briarproject/api/data/BdfDictionary.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package org.briarproject.api.data;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
public class BdfDictionary extends Hashtable<String, Object> {
|
||||
|
||||
public Boolean getBoolean(String key, Boolean defaultValue) {
|
||||
Object o = get(key);
|
||||
if (o instanceof Boolean) return (Boolean) o;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public Long getInteger(String key, Long defaultValue) {
|
||||
Object o = get(key);
|
||||
if (o instanceof Long) return (Long) o;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public Double getFloat(String key, Double defaultValue) {
|
||||
Object o = get(key);
|
||||
if (o instanceof Double) return (Double) o;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public String getString(String key, String defaultValue) {
|
||||
Object o = get(key);
|
||||
if (o instanceof String) return (String) o;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public byte[] getRaw(String key, byte[] defaultValue) {
|
||||
Object o = get(key);
|
||||
if (o instanceof byte[]) return (byte[]) o;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public BdfList getList(String key, BdfList defaultValue) {
|
||||
Object o = get(key);
|
||||
if (o instanceof BdfList) return (BdfList) o;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public BdfDictionary getDictionary(String key, BdfDictionary defaultValue) {
|
||||
Object o = get(key);
|
||||
if (o instanceof BdfDictionary) return (BdfDictionary) o;
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
48
briar-api/src/org/briarproject/api/data/BdfList.java
Normal file
48
briar-api/src/org/briarproject/api/data/BdfList.java
Normal file
@@ -0,0 +1,48 @@
|
||||
package org.briarproject.api.data;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public class BdfList extends Vector<Object> {
|
||||
|
||||
public Boolean getBoolean(int index, Boolean defaultValue) {
|
||||
Object o = get(index);
|
||||
if (o instanceof Boolean) return (Boolean) o;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public Long getInteger(int index, Long defaultValue) {
|
||||
Object o = get(index);
|
||||
if (o instanceof Long) return (Long) o;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public Double getFloat(int index, Double defaultValue) {
|
||||
Object o = get(index);
|
||||
if (o instanceof Double) return (Double) o;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public String getString(int index, String defaultValue) {
|
||||
Object o = get(index);
|
||||
if (o instanceof String) return (String) o;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public byte[] getRaw(int index, byte[] defaultValue) {
|
||||
Object o = get(index);
|
||||
if (o instanceof byte[]) return (byte[]) o;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public BdfList getList(int index, BdfList defaultValue) {
|
||||
Object o = get(index);
|
||||
if (o instanceof BdfList) return (BdfList) o;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public BdfDictionary getDictionary(int index, BdfDictionary defaultValue) {
|
||||
Object o = get(index);
|
||||
if (o instanceof BdfDictionary) return (BdfDictionary) o;
|
||||
return defaultValue;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package org.briarproject.api.data;
|
||||
|
||||
import org.briarproject.api.FormatException;
|
||||
import org.briarproject.api.db.Metadata;
|
||||
|
||||
public interface MetadataParser {
|
||||
|
||||
BdfDictionary parse(Metadata m) throws FormatException;
|
||||
}
|
||||
6
briar-api/src/org/briarproject/api/db/Metadata.java
Normal file
6
briar-api/src/org/briarproject/api/db/Metadata.java
Normal file
@@ -0,0 +1,6 @@
|
||||
package org.briarproject.api.db;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
public class Metadata extends Hashtable<String, byte[]> {
|
||||
}
|
||||
Reference in New Issue
Block a user