use of elemental2.core.ArrayBuffer in project gwtproject by treblereel.
the class GwtTzdbZoneRuleProvider method initialize.
@Override
public void initialize() {
DomGlobal.console.debug("TZDB sync initialization called");
if (!initialized) {
DomGlobal.console.debug("TZDB sync initialization started");
ScriptInjector.fromString(bundle.base64binary().getText()).setWindow(ScriptInjector.TOP_WINDOW).inject();
String tzData = bundle.tzdbEncoded().getText();
ArrayBuffer buffer = TzdbJs.decodeArrayBuffer(tzData);
ByteBuffer data = TypedArrayHelper.wrap(buffer);
ZoneRulesProvider provider = new TzdbZoneRulesProvider(data);
if (!initialized) {
ZoneRulesProvider.registerProvider(provider);
}
DomGlobal.console.debug("TZDB sync initialization finished");
initialized = true;
}
}
use of elemental2.core.ArrayBuffer in project console by hal.
the class DataInput method readDouble.
double readDouble() {
byte[] doubleBytes = new byte[8];
readFully(doubleBytes);
ArrayBuffer buffer = new ArrayBuffer(8);
Int8Array array = new Int8Array(buffer);
DataView view = new DataView(buffer);
for (int i = 0; i < doubleBytes.length; i++) {
array.setAt(i, (double) doubleBytes[i]);
}
return view.getFloat64(0);
}
use of elemental2.core.ArrayBuffer in project console by hal.
the class DataOutput method writeDouble.
void writeDouble(double v) {
ArrayBuffer buffer = new ArrayBuffer(8);
Int8Array array = new Int8Array(buffer);
DataView view = new DataView(buffer);
view.setFloat64(0, v);
for (int i = 0; i < array.getLength(); i++) {
bytes.push(array.getAt(i).byteValue());
}
}
use of elemental2.core.ArrayBuffer in project gwtproject by treblereel.
the class TzdbZoneRulesProvider method loadData.
/**
* Loads the rules from an input stream.
*
* @param in the stream to load, not null, not closed after use
* @throws Exception if an error occurs
*/
private Iterable<Version> loadData(ByteBuffer dis) throws IOException {
if (dis.get() != 1) {
// GWT change
throw new IOException("File format not recognised");
}
// group
String groupId = readUtf(dis);
if ("TZDB".equals(groupId) == false) {
// GWT change
throw new IOException("File format not recognised");
}
// versions
int versionCount = dis.getShort();
String[] versionArray = new String[versionCount];
for (int i = 0; i < versionCount; i++) {
versionArray[i] = readUtf(dis);
}
// regions
int regionCount = dis.getShort();
String[] regionArray = new String[regionCount];
for (int i = 0; i < regionCount; i++) {
regionArray[i] = readUtf(dis);
}
regionIds = Arrays.asList(regionArray);
// rules
int ruleCount = dis.getShort();
// ZoneRules[] ruleArray = new ZoneRules[ruleCount];
ArrayBuffer[] ruleArray = new ArrayBuffer[ruleCount];
for (int i = 0; i < ruleCount; i++) {
short length = dis.getShort();
ArrayBufferNative buffer = new ArrayBufferNative(length);
Int8ArrayNative array = new Int8ArrayNative(buffer);
for (int j = 0; j < length; j++) {
array.set(j, dis.get());
}
// ruleArray[i] = (ZoneRules) Ser.read(dis);
ruleArray[i] = Js.cast(buffer);
}
// link version-region-rules
Set<Version> versionSet = new HashSet<Version>(versionCount);
for (int i = 0; i < versionCount; i++) {
int versionRegionCount = dis.getShort();
String[] versionRegionArray = new String[versionRegionCount];
short[] versionRulesArray = new short[versionRegionCount];
for (int j = 0; j < versionRegionCount; j++) {
versionRegionArray[j] = regionArray[dis.getShort()];
versionRulesArray[j] = dis.getShort();
}
versionSet.add(new Version(versionArray[i], versionRegionArray, versionRulesArray, ruleArray));
}
return versionSet;
}
Aggregations