Search in sources :

Example 1 with ArrayBuffer

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;
    }
}
Also used : ZoneRulesProvider(java.time.zone.ZoneRulesProvider) ArrayBuffer(elemental2.core.ArrayBuffer) ByteBuffer(java.nio.ByteBuffer)

Example 2 with ArrayBuffer

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);
}
Also used : Int8Array(elemental2.core.Int8Array) DataView(elemental2.core.DataView) ArrayBuffer(elemental2.core.ArrayBuffer)

Example 3 with ArrayBuffer

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());
    }
}
Also used : Int8Array(elemental2.core.Int8Array) DataView(elemental2.core.DataView) ArrayBuffer(elemental2.core.ArrayBuffer)

Example 4 with ArrayBuffer

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;
}
Also used : Int8ArrayNative(org.gwtproject.typedarrays.client.Int8ArrayNative) IOException(java.io.IOException) ArrayBufferNative(org.gwtproject.typedarrays.client.ArrayBufferNative) ArrayBuffer(elemental2.core.ArrayBuffer) HashSet(java.util.HashSet)

Aggregations

ArrayBuffer (elemental2.core.ArrayBuffer)4 DataView (elemental2.core.DataView)2 Int8Array (elemental2.core.Int8Array)2 IOException (java.io.IOException)1 ByteBuffer (java.nio.ByteBuffer)1 ZoneRulesProvider (java.time.zone.ZoneRulesProvider)1 HashSet (java.util.HashSet)1 ArrayBufferNative (org.gwtproject.typedarrays.client.ArrayBufferNative)1 Int8ArrayNative (org.gwtproject.typedarrays.client.Int8ArrayNative)1