Example usage for com.google.common.primitives Longs toByteArray

List of usage examples for com.google.common.primitives Longs toByteArray

Introduction

In this page you can find the example usage for com.google.common.primitives Longs toByteArray.

Prototype

public static byte[] toByteArray(long value) 

Source Link

Document

Returns a big-endian representation of value in an 8-element byte array; equivalent to ByteBuffer.allocate(8).putLong(value).array() .

Usage

From source file:com.temenos.interaction.loader.classloader.CachingParentLastURLClassloaderFactory.java

protected Object calculateCurrentState(FileEvent<File> param) {
    Collection<File> files = FileUtils.listFiles(param.getResource(), new String[] { "jar" }, true);

    MessageDigest md = DigestUtils.getMd5Digest();
    for (File f : files) {
        md.update(Longs.toByteArray(f.lastModified()));
    }/*from   w w  w .ja v  a2s.  com*/

    Object state = Hex.encodeHexString(md.digest());
    LOGGER.trace(
            "Calculated representation /hash/ of state of collection of URLs for classloader creation to: {}",
            state);
    return state;
}

From source file:cn.codepub.redis.directory.io.JedisPoolStream.java

@Override
public void saveFile(String fileLengthKey, String fileDataKey, String fileName, List<byte[]> values,
        long fileLength) {
    Jedis jedis = null;//from   ww  w  .ja v  a2s .co  m
    try {
        jedis = jedisPool.getResource();
        Pipeline pipelined = jedis.pipelined();
        pipelined.hset(fileLengthKey.getBytes(), fileName.getBytes(), Longs.toByteArray(fileLength));
        Long blockSize = getBlockSize(fileLength);
        for (int i = 0; i < blockSize; i++) {
            pipelined.hset(fileDataKey.getBytes(), getBlockName(fileName, i), compressFilter(values.get(i)));
            if (i % Constants.SYNC_COUNT == 0) {
                pipelined.sync();
                pipelined = jedis.pipelined();
            }
        }
        values.clear();
        pipelined.sync();
    } finally {
        jedis.close();
    }
}

From source file:com.syncleus.spangraph.MapGraph.java

public String newID() {
    String r;/*w w w .  j  a va  2 s . com*/
    do {
        long low = UUID.randomUUID().getLeastSignificantBits();
        long high = UUID.randomUUID().getMostSignificantBits();
        r = new String(
                Base64.getEncoder().encode(Bytes.concat(Longs.toByteArray(low), Longs.toByteArray(high))));
    } while (this.vertices.containsKey(r));
    return r;
}

From source file:org.gaul.s3proxy.NullBlobStore.java

@Override
public MultipartPart uploadMultipartPart(MultipartUpload mpu, int partNumber, Payload payload) {
    long length;//from w ww .  java 2 s.  c o  m
    try (InputStream is = payload.openStream()) {
        length = ByteStreams.copy(is, ByteStreams.nullOutputStream());
    } catch (IOException ioe) {
        throw new RuntimeException(ioe);
    }

    byte[] array = Longs.toByteArray(length);
    ByteSourcePayload newPayload = new ByteSourcePayload(ByteSource.wrap(array));
    newPayload.setContentMetadata(payload.getContentMetadata());
    newPayload.getContentMetadata().setContentLength((long) array.length);
    newPayload.getContentMetadata().setContentMD5((HashCode) null);

    MultipartPart part = super.uploadMultipartPart(mpu, partNumber, newPayload);
    return MultipartPart.create(part.partNumber(), length, part.partETag(), part.lastModified());
}

From source file:cn.codepub.redis.directory.io.ShardedJedisPoolStream.java

@Override
public void saveFile(String fileLengthKey, String fileDataKey, String fileName, List<byte[]> values,
        long fileLength) {
    ShardedJedis shardedJedis = getShardedJedis();
    ShardedJedisPipeline pipelined = shardedJedis.pipelined();
    pipelined.hset(fileLengthKey.getBytes(), fileName.getBytes(), Longs.toByteArray(fileLength));
    Long blockSize = getBlockSize(fileLength);
    for (int i = 0; i < blockSize; i++) {
        pipelined.hset(fileDataKey.getBytes(), getBlockName(fileName, i), compressFilter(values.get(i)));
        if (i % Constants.SYNC_COUNT == 0) {
            pipelined.sync();//from www . j av a2 s . co m
            pipelined = shardedJedis.pipelined();
        }
    }
    pipelined.sync();
    shardedJedis.close();
    values.clear();
}

From source file:io.warp10.continuum.store.SlicedRowFilterGTSDecoderIterator.java

public static byte[][] getKeys(Metadata metadata, long now, long timespan) {
    // 128BITS/*  w  w  w .  j a va 2 s . c  om*/
    byte[] lower = new byte[24 + prefix.length];
    byte[] upper = new byte[lower.length];

    System.arraycopy(prefix, 0, lower, 0, prefix.length);

    System.arraycopy(Longs.toByteArray(metadata.getClassId()), 0, lower, prefix.length, 8);
    System.arraycopy(Longs.toByteArray(metadata.getLabelsId()), 0, lower, prefix.length + 8, 8);

    System.arraycopy(lower, 0, upper, 0, prefix.length + 16);

    //
    // Set lower/upper timestamps
    //

    long modulus = Constants.DEFAULT_MODULUS;

    if (Long.MAX_VALUE == now) {
        System.arraycopy(ZERO_BYTES, 0, lower, prefix.length + 16, 8);
    } else {
        System.arraycopy(Longs.toByteArray(Long.MAX_VALUE - (now - (now % modulus))), 0, lower,
                prefix.length + 16, 8);
    }

    if (timespan < 0) {
        System.arraycopy(ONES_BYTES, 0, upper, prefix.length + 16, 8);
    } else {
        // Last timestamp does not need to be offset by modulus as it is the case when using a scanner, because
        // SlicedRowFilter upper bound is included, not excluded.
        System.arraycopy(Longs.toByteArray(Long.MAX_VALUE - ((now - timespan) - ((now - timespan) % modulus))),
                0, upper, prefix.length + 16, 8);
    }

    byte[][] keys = new byte[2][];
    keys[0] = lower;
    keys[1] = upper;
    return keys;
}

From source file:com.liaison.javabasics.serialization.BytesUtil.java

/**
 * TODO/*from   w  w w. jav a2  s .  c  o  m*/
 * @param value TODO
 * @return TODO
 */
public static byte[] toBytes(final long value) {
    return Longs.toByteArray(value);
}

From source file:com.google.cloud.hadoop.gcsio.FileInfo.java

/**
 * Add a key and value representing the current time, as determined by the passed clock, to the
 * passed attributes dictionary.//w ww.  j a  va 2  s .  c  o m
 * @param attributes The file attributes map to update
 * @param clock The clock to retrieve the current time from
 */
public static void addModificationTimeToAttributes(Map<String, byte[]> attributes, Clock clock) {
    attributes.put(FILE_MODIFICATION_TIMESTAMP_KEY, Longs.toByteArray(clock.currentTimeMillis()));
}

From source file:org.dcache.pool.repository.ceph.CephFileStore.java

@Override
public BasicFileAttributeView getFileAttributeView(PnfsId id) throws IOException {
    String imageName = toImageName(id);
    try (RbdImage image = rbd.openReadOnly(imageName)) {

        final RbdImageInfo imageInfo = image.stat();

        return new BasicFileAttributeView() {
            @Override//ww w.  j a v a 2 s .co  m
            public String name() {
                return "basic";
            }

            @Override
            public BasicFileAttributes readAttributes() throws IOException {
                return new BasicFileAttributes() {

                    private FileTime getTimeFromXattr(String image, String attr) {
                        long time;
                        try {
                            byte[] b = new byte[Long.BYTES];
                            ctx.getXattr(toObjName(image), attr, b);
                            time = Longs.fromByteArray(b);
                        } catch (RadosException e) {
                            time = 0;
                        }
                        return FileTime.fromMillis(time);
                    }

                    @Override
                    public FileTime lastModifiedTime() {
                        return getTimeFromXattr(imageName, LAST_MODIFICATION_TIME_ATTR);
                    }

                    @Override
                    public FileTime lastAccessTime() {
                        return getTimeFromXattr(imageName, LAST_ACCESS_TIME_ATTR);
                    }

                    @Override
                    public FileTime creationTime() {
                        return getTimeFromXattr(imageName, CREATION_TIME_ATTR);
                    }

                    @Override
                    public boolean isRegularFile() {
                        return true;
                    }

                    @Override
                    public boolean isDirectory() {
                        return false;
                    }

                    @Override
                    public boolean isSymbolicLink() {
                        return false;
                    }

                    @Override
                    public boolean isOther() {
                        return false;
                    }

                    @Override
                    public long size() {
                        return imageInfo.obj_size.longValue();
                    }

                    @Override
                    public Object fileKey() {
                        return null;
                    }
                };
            }

            private void setTimeToXattr(String image, String attr, FileTime time) throws RadosException {
                ctx.setXattr(toObjName(image), attr, Longs.toByteArray(time.toMillis()));
            }

            @Override
            public void setTimes(FileTime lastModifiedTime, FileTime lastAccessTime, FileTime createTime)
                    throws IOException {

                if (lastModifiedTime != null) {
                    setTimeToXattr(imageName, LAST_MODIFICATION_TIME_ATTR, lastModifiedTime);
                }

                if (lastAccessTime != null) {
                    setTimeToXattr(imageName, LAST_ACCESS_TIME_ATTR, lastAccessTime);
                }

                if (createTime != null) {
                    setTimeToXattr(imageName, CREATION_TIME_ATTR, createTime);
                }

            }
        };
    } catch (RadosException e) {
        throwIfMappable(e, "Failed to get file's attribute: " + imageName);
        throw e;
    }
}

From source file:co.cask.cdap.data.stream.StreamDataFileWriter.java

@Override
public void close() throws IOException {
    if (closed) {
        return;/*  w  w w . j a  v  a  2s.c o  m*/
    }

    try {
        flushBlock(false);
        // Write the tail marker, which is a -(current timestamp).
        closeTimestamp = System.currentTimeMillis();
        eventOutput.write(Longs.toByteArray(-closeTimestamp));
    } finally {
        closed = true;
        try {
            eventOutput.close();
        } finally {
            indexOutput.close();
        }
    }
}