You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pylucene-commits@lucene.apache.org by va...@apache.org on 2014/07/07 16:31:37 UTC

svn commit: r1608472 - in /lucene/pylucene/trunk: java/org/apache/pylucene/store/PythonIndexOutput.java test/test_PyLucene.py test/test_PythonDirectory.py

Author: vajda
Date: Mon Jul  7 14:31:36 2014
New Revision: 1608472

URL: http://svn.apache.org/r1608472
Log:
adapted to changes in IndexOutput

Modified:
    lucene/pylucene/trunk/java/org/apache/pylucene/store/PythonIndexOutput.java
    lucene/pylucene/trunk/test/test_PyLucene.py
    lucene/pylucene/trunk/test/test_PythonDirectory.py

Modified: lucene/pylucene/trunk/java/org/apache/pylucene/store/PythonIndexOutput.java
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/java/org/apache/pylucene/store/PythonIndexOutput.java?rev=1608472&r1=1608471&r2=1608472&view=diff
==============================================================================
--- lucene/pylucene/trunk/java/org/apache/pylucene/store/PythonIndexOutput.java (original)
+++ lucene/pylucene/trunk/java/org/apache/pylucene/store/PythonIndexOutput.java Mon Jul  7 14:31:36 2014
@@ -16,10 +16,10 @@
 package org.apache.pylucene.store;
 
 import java.io.IOException;
-import org.apache.lucene.store.BufferedIndexOutput;
+import org.apache.lucene.store.IndexOutput;
 
 
-public class PythonIndexOutput extends BufferedIndexOutput {
+public class PythonIndexOutput extends IndexOutput {
 
     private long pythonObject;
 
@@ -42,28 +42,33 @@ public class PythonIndexOutput extends B
         pythonDecRef();
     }
 
-    public void seek(long pos)
+    public native void pythonDecRef();
+
+    public void flush()
         throws IOException
-    {
-        super.seek(pos);
-        seekInternal(pos);
-    }
+    {}
 
-    public native void pythonDecRef();
-    public native long length()
+    public native long getFilePointer();
+    public native long getChecksum()
         throws IOException;
-    public native void flushBuffer(byte[] data)
+    public native void close()
         throws IOException;
-    public native void seekInternal(long pos)
+    public native void writeByte(byte b)
         throws IOException;
-    public native void close()
+    public native void writeBytes(byte[] bytes)
         throws IOException;
 
-    protected void flushBuffer(byte[] b, int offset, int len)
+    public void writeBytes(byte[] bytes, int offset, int length)
         throws IOException
     {
-        byte[] data = new byte[len];
-        System.arraycopy(b, offset, data, 0, len);
-        flushBuffer(data);
+        if (offset > 0 || length < bytes.length)
+        {
+            byte[] data = new byte[length];
+
+            System.arraycopy(bytes, offset, data, 0, length);
+            writeBytes(data);
+        }
+        else
+            writeBytes(bytes);
     }
 }

Modified: lucene/pylucene/trunk/test/test_PyLucene.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/test/test_PyLucene.py?rev=1608472&r1=1608471&r2=1608472&view=diff
==============================================================================
--- lucene/pylucene/trunk/test/test_PyLucene.py (original)
+++ lucene/pylucene/trunk/test/test_PyLucene.py Mon Jul  7 14:31:36 2014
@@ -232,7 +232,6 @@ class Test_PyLuceneBase(object):
             self.closeStore(store)
         
     def test_FieldEnumeration(self):
-
         self.test_indexDocument()
 
         store = self.openStore()

Modified: lucene/pylucene/trunk/test/test_PythonDirectory.py
URL: http://svn.apache.org/viewvc/lucene/pylucene/trunk/test/test_PythonDirectory.py?rev=1608472&r1=1608471&r2=1608472&view=diff
==============================================================================
--- lucene/pylucene/trunk/test/test_PythonDirectory.py (original)
+++ lucene/pylucene/trunk/test/test_PythonDirectory.py Mon Jul  7 14:31:36 2014
@@ -15,6 +15,7 @@
 import sys, lucene, unittest
 import os, shutil
 import test_PyLucene 
+from binascii import crc32
 from threading import RLock
 from lucene import JavaError, JArray
 
@@ -73,7 +74,8 @@ class PythonDirLock(PythonLock):
         return self.lock.release()
 
     def close(self):
-        return self.lock.close()
+        if hasattr(self.lock, 'close'):
+            self.lock.close()
 
 
 class PythonDirLockFactory(PythonLockFactory):
@@ -140,24 +142,43 @@ class PythonFileStreamOutput(PythonIndex
         self.fh = fh
         self.isOpen = True
         self._length = 0
+        self.crc = None
 
     def close(self):
         if self.isOpen:
-            super(PythonFileStreamOutput, self).close()
             self.isOpen = False
+            self.fh.flush()
             self.fh.close()
 
-    def length(self):
+    def getFilePointer(self):
         return long(self._length)
 
-    def seekInternal(self, pos):
-        self.fh.seek(pos)
+    def getChecksum(self):
+        return long(self.crc & 0xffffffff)
 
-    def flushBuffer(self, bytes):
-
-        self.fh.write(bytes.string_)
+    def writeByte(self, b):
+        if b < 0:
+            data = chr(b + 256)
+        else:
+            data = chr(b)
+        self.fh.write(data)
+        self._length += 1
+
+        if self.crc is None:
+            self.crc = crc32(data)
+        else:
+            self.crc = crc32(data, self.crc)
+
+    def writeBytes(self, bytes):
+        data = bytes.string_
+        self.fh.write(data)
         self.fh.flush()
-        self._length += len(bytes)
+        self._length += len(data)
+
+        if self.crc is None:
+            self.crc = crc32(data)
+        else:
+            self.crc = crc32(data, self.crc)
 
 
 class PythonFileDirectory(PythonDirectory):
@@ -257,10 +278,7 @@ class PythonDirectoryTests(unittest.Test
     def closeStore(self, store, *args):
         for arg in args:
             if arg is not None:
-                try:
-                    arg.close()
-                except Exception, e:
-                    pass
+                arg.close()
         store.close()
 
     def test_IncrementalLoop(self):