Java Code Examples for com.google.common.primitives.Longs.fromByteArray()

The following are Jave code examples for showing how to use fromByteArray() of the com.google.common.primitives.Longs class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: RedisDirectory   File: RedisDirectory.java   View Source Code Vote up 6 votes
@Override
public void renameFile(String source, String dest) throws IOException {
    List<byte[]> values = new ArrayList<>();
    //在get的时候不需要加事务
    //在删除和添加的时候使用事务
    //Get the file length with old file name
    byte[] hget = inputOutputStream.hget(Constants.DIR_METADATA_BYTES, source.getBytes(), FILE_LENGTH);
    long length = Longs.fromByteArray(hget);
    long blockSize = getBlockSize(length);
    for (int i = 0; i < blockSize; i++) {
        //Get the contents with old file name
        byte[] res = inputOutputStream.hget(Constants.FILE_METADATA_BYTES, getBlockName(source, i), FILE_DATA);
        values.add(res);
    }
    inputOutputStream.rename(Constants.DIRECTORY_METADATA, Constants.FILE_METADATA, source, dest, values, length);
    log.debug("Rename file success from {} to {}", source, dest);
}
 
Example 2
Project: RedisDirectory   File: RedisDirectory.java   View Source Code Vote up 5 votes
/**
 * @param name file name
 * @return Returns the length of a file in the directory.
 * @throws IOException an I/O error
 */
@Override
public final long fileLength(String name) throws IOException {
    ensureOpen();
    long current = 0;
    byte[] b = inputOutputStream.hget(Constants.DIR_METADATA_BYTES, name.getBytes(), FILE_LENGTH);
    if (b != null) {
        current = Longs.fromByteArray(b);
    }
    return current;
}
 
Example 3
Project: RedisDirectory   File: RedisDirectory.java   View Source Code Vote up 5 votes
@Override
public void deleteFile(String name) throws IOException {
    ensureOpen();
    boolean b = fileNameExists(name);
    if (b) {
        byte[] hget = inputOutputStream.hget(Constants.DIR_METADATA_BYTES, name.getBytes(), FILE_LENGTH);
        long length = Longs.fromByteArray(hget);
        long blockSize = getBlockSize(length);
        inputOutputStream.deleteFile(Constants.DIRECTORY_METADATA, Constants.FILE_METADATA, name, blockSize);
    } else {
        log.error("Delete file {} does not exists!", name);
    }
}
 
Example 4
Project: RedisDirectory   File: RedisDirectory.java   View Source Code Vote up 5 votes
private RedisFile loadRedisToFile(String fileName) {
    byte[] hget = inputOutputStream.hget(Constants.DIR_METADATA_BYTES, fileName.getBytes(), FILE_LENGTH);
    long lenght = Longs.fromByteArray(hget);
    RedisFile redisFile = new RedisFile(fileName, lenght);
    long blockSize = getBlockSize(lenght);
    List<byte[]> bytes = inputOutputStream.loadFileOnce(Constants.FILE_METADATA, fileName, blockSize);
    redisFile.setBuffers(bytes);
    return redisFile;
}
 
Example 5
Project: hadoop   File: BestEffortLongFile.java   View Source Code Vote up 5 votes
private void lazyOpen() throws IOException {
  if (ch != null) {
    return;
  }

  // Load current value.
  byte[] data = null;
  try {
    data = Files.toByteArray(file);
  } catch (FileNotFoundException fnfe) {
    // Expected - this will use default value.
  }

  if (data != null && data.length != 0) {
    if (data.length != Longs.BYTES) {
      throw new IOException("File " + file + " had invalid length: " +
          data.length);
    }
    value = Longs.fromByteArray(data);
  } else {
    value = defaultVal;
  }
  
  // Now open file for future writes.
  RandomAccessFile raf = new RandomAccessFile(file, "rw");
  try {
    ch = raf.getChannel();
  } finally {
    if (ch == null) {
      IOUtils.closeStream(raf);
    }
  }
}
 
Example 6
Project: MantaroRPG   File: Snow64.java   View Source Code Vote up 4 votes
public static long fromSnow64(String snow64) {
	return (Longs.fromByteArray(Base64.getDecoder().decode(snow64.replace('-', '/'))));
}
 
Example 7
Project: dremio-oss   File: AbstractTestOCCKVStore.java   View Source Code Vote up 4 votes
@Override
public Value revert(byte[] v) {
  long version = Longs.fromByteArray(v);
  return new Value(version == -1 ? null : version);
}
 
Example 8
Project: util   File: NumberUtil.java   View Source Code Vote up 4 votes
public static long toLong(byte[] bytes) {
	return Longs.fromByteArray(bytes);
}