Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added CatRandomAccessFileStore to li-911

  • Loading branch information...
commit 914c000caa71d908c9cab80faa1ca4a322291e5b 1 parent e83964c
bbansal bbansal authored

Showing 1 changed file with 60 additions and 0 deletions. Show diff stats Hide diff stats

  1. +60 0 test/integration/voldemort/CatRandomAccessFileStore.java
60 test/integration/voldemort/CatRandomAccessFileStore.java
... ... @@ -0,0 +1,60 @@
  1 +/*
  2 + * Copyright 2008-2009 LinkedIn, Inc
  3 + *
  4 + * Licensed under the Apache License, Version 2.0 (the "License"); you may not
  5 + * use this file except in compliance with the License. You may obtain a copy of
  6 + * the License at
  7 + *
  8 + * http://www.apache.org/licenses/LICENSE-2.0
  9 + *
  10 + * Unless required by applicable law or agreed to in writing, software
  11 + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  12 + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  13 + * License for the specific language governing permissions and limitations under
  14 + * the License.
  15 + */
  16 +
  17 +package voldemort;
  18 +
  19 +import java.io.EOFException;
  20 +import java.io.File;
  21 +import java.io.RandomAccessFile;
  22 +
  23 +import voldemort.serialization.Serializer;
  24 +import voldemort.serialization.json.JsonTypeDefinition;
  25 +import voldemort.serialization.json.JsonTypeSerializer;
  26 +import voldemort.utils.ByteUtils;
  27 +import voldemort.utils.Utils;
  28 +
  29 +public class CatRandomAccessFileStore {
  30 +
  31 + public static void main(String[] args) throws Exception {
  32 + if(args.length != 2)
  33 + Utils.croak("USAGE: java " + CatRandomAccessFileStore.class.getName() + " directory");
  34 + File dir = new File(args[0]);
  35 + String storeName = args[1];
  36 + Serializer<Object> serializer = new JsonTypeSerializer(JsonTypeDefinition.fromJson("'string'"),
  37 + true);
  38 + RandomAccessFile index = new RandomAccessFile(new File(dir, storeName + ".index"), "r");
  39 + RandomAccessFile data = new RandomAccessFile(new File(dir, storeName + ".data"), "r");
  40 +
  41 + byte[] keyMd5 = new byte[16];
  42 + long position = -1;
  43 + try {
  44 + while(true) {
  45 + index.readFully(keyMd5);
  46 + position = index.readLong();
  47 +
  48 + data.seek(position);
  49 + int size = data.readInt();
  50 + byte[] value = new byte[size];
  51 + data.readFully(value);
  52 + System.out.println(ByteUtils.toHexString(keyMd5) + "\t=>\t"
  53 + + serializer.toObject(value).toString());
  54 + }
  55 + } catch(EOFException e) {
  56 + // no biggie
  57 + }
  58 +
  59 + }
  60 +}

0 comments on commit 914c000

Please sign in to comment.
Something went wrong with that request. Please try again.