incubator-connectors-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kwri...@apache.org
Subject svn commit: r1201996 - in /incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common: ./ IntegerValue.java LongValue.java StringValue.java
Date Tue, 15 Nov 2011 01:47:20 GMT
Author: kwright
Date: Tue Nov 15 01:47:20 2011
New Revision: 1201996

URL: http://svn.apache.org/viewvc?rev=1201996&view=rev
Log:
Basic objects used to build bigger ones.  Known problem: the Charset class is a jdk 1.6 construct

Added:
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/IntegerValue.java
  (with props)
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/LongValue.java
  (with props)
    incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringValue.java
  (with props)

Added: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/IntegerValue.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/IntegerValue.java?rev=1201996&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/IntegerValue.java
(added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/IntegerValue.java
Tue Nov 15 01:47:20 2011
@@ -0,0 +1,80 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.warthog.common;
+
+import org.apache.warthog.interfaces.*;
+
+/** Integer value, serializable.
+*/
+public class IntegerValue implements WHValue
+{
+  int value;
+  
+  public IntegerValue(int value)
+  {
+    this.value = value;
+  }
+  
+  public IntegerValue()
+  {
+  }
+  
+  public IntegerValue(byte[] bytes)
+  {
+    readObject(bytes,0);
+  }
+  
+  public byte[] serializeObject()
+  {
+    byte[] rval = new byte[sizeObject()];
+    writeObject(rval,0);
+    return rval;
+  }
+  
+  public int getValue()
+  {
+    return value;
+  }
+  
+  public int readObject(byte[] bytes, int offset)
+  {
+    value = (((int)bytes[offset]) & 0xff) +
+              ((((int)bytes[offset+1]) << 8) & 0xff00) +
+              ((((int)bytes[offset+2]) << 16) & 0xff0000) +
+              ((((int)bytes[offset+3]) << 24) & 0xff000000);
+    return offset + 4;
+  }
+  
+  public static int sizeObject()
+  {
+    return 4;
+  }
+  
+  public int writeObject(byte[] bytes, int offset)
+  {
+    bytes[offset] = (byte)(value & 0xff);
+    bytes[offset+1] = (byte)((value >> 8) & 0xff);
+    bytes[offset+2] = (byte)((value >> 16) & 0xff);
+    bytes[offset+3] = (byte)((value >> 24) & 0xff);
+    return offset + 4;
+  }
+}
+
+

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/IntegerValue.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/IntegerValue.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/LongValue.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/LongValue.java?rev=1201996&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/LongValue.java
(added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/LongValue.java
Tue Nov 15 01:47:20 2011
@@ -0,0 +1,88 @@
+/* $Id$ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.warthog.common;
+
+import org.apache.warthog.interfaces.*;
+
+/** Long value, serializable.
+*/
+public class LongValue implements WHValue
+{
+  long value;
+  
+  public LongValue(long value)
+  {
+    this.value = value;
+  }
+  
+  public LongValue()
+  {
+  }
+  
+  public LongValue(byte[] bytes)
+  {
+    readObject(bytes,0);
+  }
+  
+  public byte[] serializeObject()
+  {
+    byte[] rval = new byte[sizeObject()];
+    writeObject(rval,0);
+    return rval;
+  }
+  
+  public long getValue()
+  {
+    return value;
+  }
+  
+  public int readObject(byte[] bytes, int offset)
+  {
+    value = (((long)bytes[offset]) & 0xffL) +
+              ((((long)bytes[offset+1]) << 8) & 0xff00L) +
+              ((((long)bytes[offset+2]) << 16) & 0xff0000L) +
+              ((((long)bytes[offset+3]) << 24) & 0xff000000L) +
+              ((((long)bytes[offset+4]) << 32) & 0xff00000000L) +
+              ((((long)bytes[offset+5]) << 40) & 0xff0000000000L) +
+              ((((long)bytes[offset+6]) << 48) & 0xff000000000000L) +
+              ((((long)bytes[offset+7]) << 56) & 0xff00000000000000L);
+    return offset + 8;
+  }
+  
+  public static int sizeObject()
+  {
+    return 8;
+  }
+  
+  public int writeObject(byte[] bytes, int offset)
+  {
+    bytes[offset] = (byte)(value & 0xffL);
+    bytes[offset+1] = (byte)((value >> 8) & 0xffL);
+    bytes[offset+2] = (byte)((value >> 16) & 0xffL);
+    bytes[offset+3] = (byte)((value >> 24) & 0xffL);
+    bytes[offset+4] = (byte)((value >> 32) & 0xffL);
+    bytes[offset+5] = (byte)((value >> 40) & 0xffL);
+    bytes[offset+6] = (byte)((value >> 48) & 0xffL);
+    bytes[offset+7] = (byte)((value >> 56) & 0xffL);
+    return offset + 8;
+  }
+}
+
+

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/LongValue.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/LongValue.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringValue.java
URL: http://svn.apache.org/viewvc/incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringValue.java?rev=1201996&view=auto
==============================================================================
--- incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringValue.java
(added)
+++ incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringValue.java
Tue Nov 15 01:47:20 2011
@@ -0,0 +1,92 @@
+/* $Id: WHValue.java 1199794 2011-11-09 15:28:08Z kwright $ */
+
+/**
+* Licensed to the Apache Software Foundation (ASF) under one or more
+* contributor license agreements. See the NOTICE file distributed with
+* this work for additional information regarding copyright ownership.
+* The ASF licenses this file to You under the Apache License, Version 2.0
+* (the "License"); you may not use this file except in compliance with
+* the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+package org.apache.warthog.common;
+
+import org.apache.warthog.interfaces.*;
+
+import java.nio.charset.Charset;
+
+/** This object represents a string that can be stored in the key/value store.
+*/
+public class StringValue implements WHValue
+{
+  protected static Charset UTF_8;
+  
+  static
+  {
+    try
+    {
+      UTF_8 = Charset.forName("utf-8");
+    }
+    catch (Exception e)
+    {
+    }
+  }
+  
+  protected String value;
+  
+  public StringValue(String value)
+  {
+    this.value = value;
+  }
+  
+  public StringValue()
+  {
+    value = null;
+  }
+
+  public String getValue()
+  {
+    return value;
+  }
+
+  public byte[] serializeObject()
+  {
+    byte[] rval = new byte[sizeObject()];
+    writeObject(rval,0);
+    return rval;
+  }
+
+  public int readObject(byte[] bytes, int offset)
+  {
+    IntegerValue iv = new IntegerValue();
+    offset = iv.readObject(bytes,offset);
+    int lengthValue = iv.getValue();
+    value = new String(bytes,offset,lengthValue,UTF_8);
+    offset += lengthValue;
+    return offset;
+  }
+  
+  public int sizeObject()
+  {
+    return IntegerValue.sizeObject() + value.getBytes(UTF_8).length;
+  }
+  
+  public int writeObject(byte[] bytes, int offset)
+  {
+    byte[] utf8 = value.getBytes(UTF_8);
+    IntegerValue iv = new IntegerValue(utf8.length);
+    offset = iv.writeObject(bytes,offset);
+    System.arraycopy(utf8,0,bytes,offset,utf8.length);
+    offset += utf8.length;
+    return offset;
+  }
+
+}
\ No newline at end of file

Propchange: incubator/lcf/branches/CONNECTORS-286/warthog/src/main/java/org/apache/warthog/common/StringValue.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message