Index: lucene/core/src/java/org/apache/lucene/codecs/compressing/GrowableByteArrayDataOutput.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/compressing/GrowableByteArrayDataOutput.java	(révision 1439326)
+++ lucene/core/src/java/org/apache/lucene/codecs/compressing/GrowableByteArrayDataOutput.java	(copie de travail)
@@ -25,12 +25,12 @@
 /**
  * A {@link DataOutput} that can be used to build a byte[].
  */
-final class GrowableByteArrayDataOutput extends DataOutput {
+public final class GrowableByteArrayDataOutput extends DataOutput {
 
-  byte[] bytes;
-  int length;
+  public byte[] bytes;
+  public int length;
 
-  GrowableByteArrayDataOutput(int cp) {
+  public GrowableByteArrayDataOutput(int cp) {
     this.bytes = new byte[ArrayUtil.oversize(cp, 1)];
     this.length = 0;
   }
Index: lucene/core/src/java/org/apache/lucene/codecs/compressing/LZ4.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/compressing/LZ4.java	(révision 1439326)
+++ lucene/core/src/java/org/apache/lucene/codecs/compressing/LZ4.java	(copie de travail)
@@ -30,7 +30,7 @@
  * http://code.google.com/p/lz4/
  * http://fastcompression.blogspot.fr/p/lz4.html
  */
-final class LZ4 {
+public final class LZ4 {
 
   private LZ4() {}
 
@@ -181,7 +181,7 @@
     }
   }
 
-  static final class HashTable {
+  public static final class HashTable {
     private int hashLog;
     private PackedInts.Mutable hashTable;
 
@@ -272,7 +272,7 @@
     m2.ref = m1.ref;
   }
 
-  static final class HCHashTable {
+  public static final class HCHashTable {
     static final int MAX_ATTEMPTS = 256;
     static final int MASK = MAX_DISTANCE - 1;
     int nextToUpdate;
@@ -280,7 +280,7 @@
     private final int[] hashTable;
     private final short[] chainTable;
 
-    HCHashTable() {
+    public HCHashTable() {
       hashTable = new int[HASH_TABLE_SIZE_HC];
       chainTable = new short[MAX_DISTANCE];
     }
Index: lucene/core/src/java/org/apache/lucene/codecs/BlockTreeTermsReader.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/BlockTreeTermsReader.java	(révision 1439326)
+++ lucene/core/src/java/org/apache/lucene/codecs/BlockTreeTermsReader.java	(copie de travail)
@@ -27,6 +27,7 @@
 import java.util.Locale;
 import java.util.TreeMap;
 
+import org.apache.lucene.codecs.compressing.LZ4;
 import org.apache.lucene.index.CorruptIndexException;
 import org.apache.lucene.index.DocsAndPositionsEnum;
 import org.apache.lucene.index.DocsEnum;
@@ -712,7 +713,9 @@
           if (suffixBytes.length < numBytes) {
             suffixBytes = new byte[ArrayUtil.oversize(numBytes, 1)];
           }
-          in.readBytes(suffixBytes, 0, numBytes);
+          //in.readBytes(suffixBytes, 0, numBytes);
+          final int decompressedLen = LZ4.decompress(in, numBytes, suffixBytes, 0);
+          if (decompressedLen != numBytes) throw new IOException();
           suffixesReader.reset(suffixBytes, 0, numBytes);
 
           // stats
@@ -2372,7 +2375,9 @@
           if (suffixBytes.length < numBytes) {
             suffixBytes = new byte[ArrayUtil.oversize(numBytes, 1)];
           }
-          in.readBytes(suffixBytes, 0, numBytes);
+          //in.readBytes(suffixBytes, 0, numBytes);
+          final int decompressedLen = LZ4.decompress(in, numBytes, suffixBytes, 0);
+          if (decompressedLen != numBytes) throw new IOException();
           suffixesReader.reset(suffixBytes, 0, numBytes);
 
           /*if (DEBUG) {
Index: lucene/core/src/java/org/apache/lucene/codecs/BlockTreeTermsWriter.java
===================================================================
--- lucene/core/src/java/org/apache/lucene/codecs/BlockTreeTermsWriter.java	(révision 1439326)
+++ lucene/core/src/java/org/apache/lucene/codecs/BlockTreeTermsWriter.java	(copie de travail)
@@ -22,6 +22,8 @@
 import java.util.Comparator;
 import java.util.List;
 
+import org.apache.lucene.codecs.compressing.GrowableByteArrayDataOutput;
+import org.apache.lucene.codecs.compressing.LZ4;
 import org.apache.lucene.index.FieldInfo.IndexOptions;
 import org.apache.lucene.index.FieldInfo;
 import org.apache.lucene.index.FieldInfos;
@@ -179,12 +181,12 @@
   /** Suggested default value for the {@code
    *  minItemsInBlock} parameter to {@link
    *  #BlockTreeTermsWriter(SegmentWriteState,PostingsWriterBase,int,int)}. */
-  public final static int DEFAULT_MIN_BLOCK_SIZE = 25;
+  public final static int DEFAULT_MIN_BLOCK_SIZE = 25; //50;
 
   /** Suggested default value for the {@code
    *  maxItemsInBlock} parameter to {@link
    *  #BlockTreeTermsWriter(SegmentWriteState,PostingsWriterBase,int,int)}. */
-  public final static int DEFAULT_MAX_BLOCK_SIZE = 48;
+  public final static int DEFAULT_MAX_BLOCK_SIZE = 48; //98;
 
   //public final static boolean DEBUG = false;
   //private final static boolean SAVE_DOT_FILES = false;
@@ -783,6 +785,8 @@
       }
     }
 
+    private final LZ4.HCHashTable ht = new LZ4.HCHashTable();
+    
     // Writes all entries in the pending slice as a single
     // block: 
     private PendingBlock writeBlock(IntsRef prevTerm, int prefixLength, int indexPrefixLength, int startBackwards, int length,
@@ -921,9 +925,16 @@
       // search on lookup
 
       // Write suffixes byte[] blob to terms dict output:
-      out.writeVInt((int) (bytesWriter.getFilePointer() << 1) | (isLeafBlock ? 1:0));
+      /*out.writeVInt((int) (bytesWriter.getFilePointer() << 1) | (isLeafBlock ? 1:0));
       bytesWriter.writeTo(out);
-      bytesWriter.reset();
+      bytesWriter.reset();*/
+      out.writeVInt((bytesWriter.length << 1) | (isLeafBlock ? 1:0));
+      //long before = out.getFilePointer();
+      LZ4.compressHC(bytesWriter.bytes, 0, bytesWriter.length, out, ht);
+      /*long after = out.getFilePointer();
+      System.out.println("Length: " + bytesWriter.length + " " + minItemsInBlock + " " + maxItemsInBlock);
+      System.out.println("Compression ratio: " + (float) (after-before) / bytesWriter.length);*/
+      bytesWriter.length = 0;
 
       // Write term stats byte[] blob
       out.writeVInt((int) bytesWriter2.getFilePointer());
@@ -1046,7 +1057,7 @@
       }
     }
 
-    private final RAMOutputStream bytesWriter = new RAMOutputStream();
+    private final GrowableByteArrayDataOutput bytesWriter = new GrowableByteArrayDataOutput(256);
     private final RAMOutputStream bytesWriter2 = new RAMOutputStream();
   }
 
