You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@manifoldcf.apache.org by kw...@apache.org on 2013/02/06 21:41:44 UTC
svn commit: r1443199 - in
/manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml:
ByteBuffer.java CharacterBuffer.java PrefixedReader.java
Author: kwright
Date: Wed Feb 6 20:41:44 2013
New Revision: 1443199
URL: http://svn.apache.org/viewvc?rev=1443199&view=rev
Log:
Add prefixed reader class
Added:
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/CharacterBuffer.java (with props)
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/PrefixedReader.java (with props)
Modified:
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/ByteBuffer.java
Modified: manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/ByteBuffer.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/ByteBuffer.java?rev=1443199&r1=1443198&r2=1443199&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/ByteBuffer.java (original)
+++ manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/ByteBuffer.java Wed Feb 6 20:41:44 2013
@@ -19,12 +19,19 @@
package org.apache.manifoldcf.core.fuzzyml;
import org.apache.manifoldcf.core.interfaces.*;
+import java.util.*;
/** This class represents a variable-length buffer for bytes.
*/
public class ByteBuffer
{
- // MHL
+ protected static final int arraySize = 65536;
+ protected static final int arrayShift = 16;
+
+ protected final List<byte[]> arrayOfArrays = new ArrayList<byte[]>();
+ protected int totalBytes = 0;
+ protected int currentIndex = -1;
+ protected byte[] currentBuffer = null;
/** Constructor */
public ByteBuffer()
@@ -35,30 +42,40 @@ public class ByteBuffer
*/
public void clear()
{
- // MHL
+ arrayOfArrays.clear();
+ totalBytes = 0;
+ currentIndex = -1;
+ currentBuffer = null;
}
/** Get the current buffer length.
*/
public int size()
{
- // MHL
- return 0;
+ return totalBytes;
}
/** Add a byte to the buffer at the end.
*/
public void appendByte(byte b)
{
- // MHL
+ if (currentIndex == arraySize || currentIndex == -1)
+ {
+ currentBuffer = new byte[arraySize];
+ arrayOfArrays.add(currentBuffer);
+ currentIndex = 0;
+ }
+ currentBuffer[currentIndex++] = b;
+ totalBytes++;
}
/** Read a byte from the buffer from the specified place.
*/
public byte readByte(int position)
{
- // MHL
- return (byte)0;
+ int arrayNumber = position >> 16;
+ int offset = position & (arraySize-1);
+ return arrayOfArrays.get(arrayNumber)[offset];
}
}
Added: manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/CharacterBuffer.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/CharacterBuffer.java?rev=1443199&view=auto
==============================================================================
--- manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/CharacterBuffer.java (added)
+++ manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/CharacterBuffer.java Wed Feb 6 20:41:44 2013
@@ -0,0 +1,81 @@
+/* $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.manifoldcf.core.fuzzyml;
+
+import org.apache.manifoldcf.core.interfaces.*;
+import java.util.*;
+
+/** This class represents a variable-length buffer for characters.
+*/
+public class CharacterBuffer
+{
+ protected static final int arraySize = 65536;
+ protected static final int arrayShift = 16;
+
+ protected final List<char[]> arrayOfArrays = new ArrayList<char[]>();
+ protected int totalChars = 0;
+ protected int currentIndex = -1;
+ protected char[] currentBuffer = null;
+
+ /** Constructor */
+ public CharacterBuffer()
+ {
+ }
+
+ /** Clear the buffer.
+ */
+ public void clear()
+ {
+ arrayOfArrays.clear();
+ totalChars = 0;
+ currentIndex = -1;
+ currentBuffer = null;
+ }
+
+ /** Get the current buffer length.
+ */
+ public int size()
+ {
+ return totalChars;
+ }
+
+ /** Add a char to the buffer at the end.
+ */
+ public void appendChar(char b)
+ {
+ if (currentIndex == arraySize || currentIndex == -1)
+ {
+ currentBuffer = new char[arraySize];
+ arrayOfArrays.add(currentBuffer);
+ currentIndex = 0;
+ }
+ currentBuffer[currentIndex++] = b;
+ totalChars++;
+ }
+
+ /** Read a byte from the buffer from the specified place.
+ */
+ public char readChar(int position)
+ {
+ int arrayNumber = position >> 16;
+ int offset = position & (arraySize-1);
+ return arrayOfArrays.get(arrayNumber)[offset];
+ }
+
+}
Propchange: manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/CharacterBuffer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/CharacterBuffer.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/PrefixedReader.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/PrefixedReader.java?rev=1443199&view=auto
==============================================================================
--- manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/PrefixedReader.java (added)
+++ manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/PrefixedReader.java Wed Feb 6 20:41:44 2013
@@ -0,0 +1,115 @@
+/* $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.manifoldcf.core.fuzzyml;
+
+import org.apache.manifoldcf.core.interfaces.*;
+import java.io.*;
+import java.nio.*;
+
+/** This class represents a Reader that begins with characters
+* passed to it through the constructor, and then continues with the characters
+* from a wrapped Reader. It's basically used when
+* we've read past where we want to be in a Reader and need to back up.
+*/
+public class PrefixedReader extends Reader
+{
+ protected final CharacterBuffer chars;
+ protected final Reader remainderStream;
+
+ protected int charPosition = 0;
+ protected int charMax;
+
+ /** Constructor */
+ public PrefixedReader(CharacterBuffer chars, Reader remainderStream)
+ {
+ this.chars = chars;
+ this.remainderStream = remainderStream;
+ charMax = chars.size();
+ }
+
+ @Override
+ public int read(CharBuffer target)
+ throws IOException
+ {
+ if (charPosition < charMax)
+ return super.read(target);
+ return remainderStream.read(target);
+ }
+
+ @Override
+ public int read()
+ throws IOException
+ {
+ if (charPosition < charMax)
+ return super.read();
+ return remainderStream.read();
+ }
+
+ @Override
+ public int read(char[] cbuf)
+ throws IOException
+ {
+ if (charPosition < charMax)
+ return super.read(cbuf);
+ return remainderStream.read(cbuf);
+ }
+
+ @Override
+ public int read(char[] cbuf, int off, int len)
+ throws IOException
+ {
+ int amt = 0;
+ while (charPosition < charMax)
+ {
+ cbuf[off++] = chars.readChar(charPosition++);
+ len--;
+ amt++;
+ }
+ if (len > 0)
+ {
+ int rem = remainderStream.read(cbuf,off,len);
+ if (rem == -1)
+ {
+ if (amt > 0)
+ return amt;
+ return rem;
+ }
+ amt += rem;
+ }
+ return amt;
+ }
+
+ @Override
+ public long skip(long n)
+ throws IOException
+ {
+ if (charPosition < charMax)
+ return super.skip(n);
+ return remainderStream.skip(n);
+ }
+
+ @Override
+ public void close()
+ throws IOException
+ {
+ // Since the wrapped reader will be closed by someone else,
+ // we NEVER close it through the wrapper.
+ }
+
+}
Propchange: manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/PrefixedReader.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/PrefixedReader.java
------------------------------------------------------------------------------
svn:keywords = Id