Search in sources :

Example 11 with SimpleByteArrayInputStream

use of herddb.utils.SimpleByteArrayInputStream in project herddb by diennea.

the class Index method deserialize.

@SuppressFBWarnings("OS_OPEN_STREAM")
public static Index deserialize(byte[] data) {
    try {
        SimpleByteArrayInputStream ii = new SimpleByteArrayInputStream(data);
        ExtendedDataInputStream dii = new ExtendedDataInputStream(ii);
        // version
        long iversion = dii.readVLong();
        // flags for future implementations
        long iflags = dii.readVLong();
        if (iversion != 1 || iflags != 0) {
            throw new IOException("corrupted index file");
        }
        String tablespace = dii.readUTF();
        String name = dii.readUTF();
        String uuid = dii.readUTF();
        String table = dii.readUTF();
        // extensible for future implementations
        int properties = dii.readVInt();
        boolean unique = false;
        if ((properties & PROPERTY_UNIQUE) == PROPERTY_UNIQUE) {
            unique = true;
        }
        String type = dii.readUTF();
        int ncols = dii.readVInt();
        Column[] columns = new Column[ncols];
        for (int i = 0; i < ncols; i++) {
            // version
            long cversion = dii.readVLong();
            // flags for future implementations
            long cflags = dii.readVLong();
            if (cversion != 1 || cflags != 0) {
                throw new IOException("corrupted index file");
            }
            String cname = dii.readUTF();
            int ctype = dii.readVInt();
            int serialPosition = dii.readVInt();
            // for future implementations
            dii.readVInt();
            columns[i] = Column.column(cname, ctype, serialPosition);
        }
        return new Index(uuid, name, table, tablespace, type, columns, unique);
    } catch (IOException err) {
        throw new IllegalArgumentException(err);
    }
}
Also used : ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) IOException(java.io.IOException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 12 with SimpleByteArrayInputStream

use of herddb.utils.SimpleByteArrayInputStream in project herddb by diennea.

the class LedgersInfo method deserialize.

public static LedgersInfo deserialize(byte[] data, int zkVersion) {
    if (data == null || data.length == 0) {
        LedgersInfo info = new LedgersInfo();
        info.setZkVersion(zkVersion);
        return info;
    }
    try {
        LedgersInfo info = MAPPER.readValue(new SimpleByteArrayInputStream(data), LedgersInfo.class);
        info.setZkVersion(zkVersion);
        return info;
    } catch (IOException impossible) {
        throw new RuntimeException(impossible);
    }
}
Also used : SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) IOException(java.io.IOException)

Example 13 with SimpleByteArrayInputStream

use of herddb.utils.SimpleByteArrayInputStream in project herddb by diennea.

the class BookKeeperDataStorageManager method readIndexStatusFromFile.

public IndexStatus readIndexStatusFromFile(byte[] fileContent, String checkpointsFile) throws DataStorageManagerException {
    try {
        if (fileContent == null) {
            throw new DataStorageManagerException("Missing znode for " + checkpointsFile + " IndexStatusFile");
        }
        XXHash64Utils.verifyBlockWithFooter(fileContent, 0, fileContent.length);
        try (InputStream input = new SimpleByteArrayInputStream(fileContent);
            ExtendedDataInputStream dataIn = new ExtendedDataInputStream(input)) {
            // version
            long version = dataIn.readVLong();
            // flags for future implementations
            long flags = dataIn.readVLong();
            if (version != 1 || flags != 0) {
                throw new DataStorageManagerException("corrupted index status file " + checkpointsFile);
            }
            return IndexStatus.deserialize(dataIn);
        }
    } catch (IOException err) {
        throw new DataStorageManagerException(err);
    }
}
Also used : DataStorageManagerException(herddb.storage.DataStorageManagerException) ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) ExtendedDataInputStream(herddb.utils.ExtendedDataInputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) InputStream(java.io.InputStream) SimpleByteArrayInputStream(herddb.utils.SimpleByteArrayInputStream) IOException(java.io.IOException)

Aggregations

SimpleByteArrayInputStream (herddb.utils.SimpleByteArrayInputStream)13 ExtendedDataInputStream (herddb.utils.ExtendedDataInputStream)12 IOException (java.io.IOException)11 InputStream (java.io.InputStream)8 DataStorageManagerException (herddb.storage.DataStorageManagerException)7 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2 ODirectFileInputStream (herddb.utils.ODirectFileInputStream)2 BufferedInputStream (java.io.BufferedInputStream)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 LogSequenceNumber (herddb.log.LogSequenceNumber)1 MetadataStorageManagerException (herddb.metadata.MetadataStorageManagerException)1 TableSpace (herddb.model.TableSpace)1 TableStatus (herddb.storage.TableStatus)1 Bytes (herddb.utils.Bytes)1 RawString (herddb.utils.RawString)1