You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by us...@apache.org on 2012/01/05 00:36:08 UTC

svn commit: r1227387 - in /lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src: java/org/apache/lucene/analysis/kuromoji/dict/ resources/org/apache/lucene/analysis/kuromoji/dict/

Author: uschindler
Date: Wed Jan  4 23:36:07 2012
New Revision: 1227387

URL: http://svn.apache.org/viewvc?rev=1227387&view=rev
Log:
LUCENE-3305: remove useless serialization from ConnectionCosts, add codec header

Modified:
    lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/ConnectionCosts.java
    lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary.java
    lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/cc.dat

Modified: lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/ConnectionCosts.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/ConnectionCosts.java?rev=1227387&r1=1227386&r2=1227387&view=diff
==============================================================================
--- lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/ConnectionCosts.java (original)
+++ lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/ConnectionCosts.java Wed Jan  4 23:36:07 2012
@@ -23,20 +23,27 @@ import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.ObjectInputStream;
-import java.io.ObjectOutputStream;
-import java.io.Serializable;
+import java.io.OutputStream;
 
-public class ConnectionCosts implements Serializable{
-  
-  private static final long serialVersionUID = -7704592689635266457L;
+import org.apache.lucene.store.DataInput;
+import org.apache.lucene.store.DataOutput;
+import org.apache.lucene.store.InputStreamDataInput;
+import org.apache.lucene.store.OutputStreamDataOutput;
+import org.apache.lucene.util.CodecUtil;
+
+public class ConnectionCosts {
   
   public static final String FILENAME = "cc.dat";
+  public static final String HEADER = "kuromoji_cc";
+  public static final int VERSION = 1;
   
   private short[][] costs; // array is backward IDs first since get is called using the same backward ID consecutively. maybe doesn't matter.
   
   public ConnectionCosts() {
-    
+  }
+  
+  private ConnectionCosts(short[][] costs) {
+    this.costs = costs;
   }
   
   public ConnectionCosts(int forwardSize, int backwardSize) {
@@ -60,9 +67,21 @@ public class ConnectionCosts implements 
   
   public void write(String directoryname) throws IOException {
     String filename = directoryname + File.separator + FILENAME;
-    ObjectOutputStream outputStream = new ObjectOutputStream(new BufferedOutputStream(new FileOutputStream(filename)));
-    outputStream.writeObject(this);
-    outputStream.close();
+    OutputStream os = new FileOutputStream(filename);
+    try {
+      os = new BufferedOutputStream(os);
+      final DataOutput out = new OutputStreamDataOutput(os);
+      CodecUtil.writeHeader(out, HEADER, VERSION);
+      out.writeVInt(costs.length);
+      for (short[] a : costs) {
+        out.writeVInt(a.length);
+        for (int i = 0; i < a.length; i++) {
+          out.writeShort(a[i]);
+        }
+      }
+    } finally {
+      os.close();
+    }
   }
   
   public static ConnectionCosts getInstance() throws IOException, ClassNotFoundException {
@@ -71,10 +90,23 @@ public class ConnectionCosts implements 
   }
   
   public static ConnectionCosts read(InputStream is) throws IOException, ClassNotFoundException {
-    ObjectInputStream ois = new ObjectInputStream(new BufferedInputStream(is));
-    ConnectionCosts instance = (ConnectionCosts) ois.readObject();
-    ois.close();
-    return instance;
+    is = new BufferedInputStream(is);
+    try {
+      final DataInput in = new InputStreamDataInput(is);
+      CodecUtil.checkHeader(in, HEADER, VERSION, VERSION);
+      final short[][] costs = new short[in.readVInt()][];
+      for (int j = 0; j < costs.length; j++) {
+        final int len = in.readVInt();
+        final short[] a = new short[len];
+        for (int i = 0; i < len; i++) {
+          a[i] = in.readShort();
+        }
+        costs[j] = a;
+      }
+      return new ConnectionCosts(costs);
+    } finally {
+      is.close();
+    }
   }
   
 }

Modified: lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary.java?rev=1227387&r1=1227386&r2=1227387&view=diff
==============================================================================
--- lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary.java (original)
+++ lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/java/org/apache/lucene/analysis/kuromoji/dict/TokenInfoDictionary.java Wed Jan  4 23:36:07 2012
@@ -248,6 +248,7 @@ public class TokenInfoDictionary impleme
       // Write Buffer
       buffer.flip();  // set position to 0, set limit to current position
       channel.write(buffer);
+      assert buffer.remaining() == 0L;
     } finally {
       os.close();
     }

Modified: lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/cc.dat
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene3305/modules/analysis/kuromoji/src/resources/org/apache/lucene/analysis/kuromoji/dict/cc.dat?rev=1227387&r1=1227386&r2=1227387&view=diff
==============================================================================
Binary files - no diff available.