Author: kwright
Date: Fri Feb 8 08:33:41 2013
New Revision: 1443879
URL: http://svn.apache.org/r1443879
Log:
Revamp the receiver API's; they didn't need to be so clumsy.
Removed:
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/PretagEncodingDetector.java
Modified:
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/ByteReceiver.java
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/CharacterReceiver.java
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/DecodingByteReceiver.java
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/Parser.java
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/SingleByteReceiver.java
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/SingleCharacterReceiver.java
Modified:
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/ByteReceiver.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/ByteReceiver.java?rev=1443879&r1=1443878&r2=1443879&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/ByteReceiver.java
(original)
+++
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/ByteReceiver.java
Fri Feb 8 08:33:41 2013
@@ -27,31 +27,18 @@ import java.io.*;
*/
public abstract class ByteReceiver
{
- protected InputStream inputStream = null;
-
/** Constructor */
public ByteReceiver()
{
}
- /** Set the input stream. The input stream must be
- * at the point where the bytes being received would start.
- * The stream is expected to be closed by the caller, when
- * the operations are all done.
- */
- public void setInputStream(InputStream is)
- throws IOException
- {
- this.inputStream = is;
- }
-
- /** Read the byte stream and process a limited chunk of bytes,
- *@return true if end reached.
+ /** Read a byte stream and process bytes.
+ *@return true if abort signalled, false if end of stream reached.
*/
- public abstract boolean dealWithBytes()
+ public abstract boolean dealWithBytes(InputStream is)
throws IOException, ManifoldCFException;
- /** Finish up all processing.
+ /** Finish up all processing. Called ONLY if we haven't already aborted.
*/
public void finishUp()
throws ManifoldCFException
Modified:
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/CharacterReceiver.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/CharacterReceiver.java?rev=1443879&r1=1443878&r2=1443879&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/CharacterReceiver.java
(original)
+++
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/CharacterReceiver.java
Fri Feb 8 08:33:41 2013
@@ -25,31 +25,19 @@ import java.io.*;
*/
public abstract class CharacterReceiver
{
- protected Reader reader = null;
-
/** Constructor.
*/
public CharacterReceiver()
{
}
- /** Set the reader we'll be getting characters from.
- * It is the caller's responsibility to close this when
- * the caller has no further use for this CharacterReceiver.
- */
- public void setReader(Reader reader)
- throws IOException
- {
- this.reader = reader;
- }
-
- /** Receive a set of characters; process one chunk worth.
- *@return true if done.
+ /** Receive a stream of characters.
+ *@return true if abort signalled, false if end of stream.
*/
- public abstract boolean dealWithCharacters()
+ public abstract boolean dealWithCharacters(Reader reader)
throws IOException, ManifoldCFException;
- /** Finish up all processing.
+ /** Finish up all processing. Called ONLY if we haven't already aborted.
*/
public void finishUp()
throws ManifoldCFException
Modified:
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/DecodingByteReceiver.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/DecodingByteReceiver.java?rev=1443879&r1=1443878&r2=1443879&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/DecodingByteReceiver.java
(original)
+++
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/DecodingByteReceiver.java
Fri Feb 8 08:33:41 2013
@@ -30,36 +30,22 @@ public class DecodingByteReceiver extend
protected final String charSet;
public DecodingByteReceiver(int chunkSize, String charSet, CharacterReceiver
charReceiver)
- throws IOException
{
super();
this.charSet = charSet;
this.charReceiver = charReceiver;
}
- /** Set the input stream. The input stream must be
- * at the point where the bytes being received would start.
- * The stream is expected to be closed by the caller, when
- * the operations are all done.
+ /** Read a byte stream and process bytes.
+ *@return true if abort signalled, false if end of stream reached.
*/
@Override
- public void setInputStream(InputStream is)
- throws IOException
+ public final boolean dealWithBytes(InputStream is)
+ throws IOException, ManifoldCFException
{
- super.setInputStream(is);
// Create a reader based on the encoding and the input stream
Reader reader = new InputStreamReader(is,charSet);
- charReceiver.setReader(reader);
- }
-
- /** Receive a byte stream and process up to chunksize bytes,
- *@return true if end reached.
- */
- @Override
- public boolean dealWithBytes()
- throws IOException, ManifoldCFException
- {
- return charReceiver.dealWithCharacters();
+ return charReceiver.dealWithCharacters(reader);
}
/** Finish up all processing.
Modified:
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/Parser.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/Parser.java?rev=1443879&r1=1443878&r2=1443879&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/Parser.java
(original)
+++
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/Parser.java
Fri Feb 8 08:33:41 2013
@@ -55,19 +55,8 @@ public class Parser
// First go-around: use the BOM detector with nothing downstream, since we
don't know the character set yet.
BOMEncodingDetector bomEncodingDetector = new BOMEncodingDetector(null);
bomEncodingDetector.setEncoding(startingCharset);
- bomEncodingDetector.setInputStream(replayableInputStream);
- try
- {
- while (true)
- {
- if (bomEncodingDetector.dealWithBytes())
- break;
- }
- }
- finally
- {
+ if (bomEncodingDetector.dealWithBytes(replayableInputStream) == false)
bomEncodingDetector.finishUp();
- }
// Update our notion of what the character set is
startingCharset = bomEncodingDetector.getEncoding();
@@ -81,19 +70,8 @@ public class Parser
xmlEncodingDetector.setEncoding(startingCharset);
bomEncodingDetector = new BOMEncodingDetector(new
DecodingByteReceiver(1024,startingCharset,xmlEncodingDetector));
// Rerun the detection; this should finalize the value.
- bomEncodingDetector.setInputStream(replayableInputStream);
- try
- {
- while (true)
- {
- if (bomEncodingDetector.dealWithBytes())
- break;
- }
- }
- finally
- {
+ if (bomEncodingDetector.dealWithBytes(replayableInputStream) == false)
bomEncodingDetector.finishUp();
- }
// Get the final charset determination
startingCharset = xmlEncodingDetector.getEncoding();
@@ -101,19 +79,8 @@ public class Parser
replayableInputStream.restart(true);
// Set up the whole chain and parse
bomEncodingDetector = new BOMEncodingDetector(new
DecodingByteReceiver(65536,startingCharset,characterReceiver));
- bomEncodingDetector.setInputStream(replayableInputStream);
- try
- {
- while (true)
- {
- if (bomEncodingDetector.dealWithBytes())
- break;
- }
- }
- finally
- {
+ if (bomEncodingDetector.dealWithBytes(replayableInputStream) == false)
bomEncodingDetector.finishUp();
- }
}
/** Parse an input stream without character set detection.
@@ -127,21 +94,9 @@ public class Parser
if (startingCharset == null)
startingCharset = "utf-8";
ByteReceiver byteReceiver = new DecodingByteReceiver(65536,
startingCharset, characterReceiver);
- // Set the input stream.
- byteReceiver.setInputStream(inputStream);
- try
- {
- // Process until done
- while (true)
- {
- if (byteReceiver.dealWithBytes())
- break;
- }
- }
- finally
- {
+ // Process to completion
+ if (byteReceiver.dealWithBytes(inputStream) == false)
byteReceiver.finishUp();
- }
}
}
Modified:
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/SingleByteReceiver.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/SingleByteReceiver.java?rev=1443879&r1=1443878&r2=1443879&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/SingleByteReceiver.java
(original)
+++
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/SingleByteReceiver.java
Fri Feb 8 08:33:41 2013
@@ -33,22 +33,24 @@ public abstract class SingleByteReceiver
byteBuffer = new byte[chunkSize];
}
- /** Read the byte stream and process up to chunksize bytes,
- *@return true if end reached.
+ /** Read a byte stream and process bytes.
+ *@return true if abort signalled, false if end of stream reached.
*/
@Override
- public boolean dealWithBytes()
+ public final boolean dealWithBytes(InputStream inputStream)
throws IOException, ManifoldCFException
{
- int amt = inputStream.read(byteBuffer);
- if (amt == -1)
- return true;
- for (int i = 0; i < amt; i++)
+ while (true)
{
- if (dealWithByte(byteBuffer[i]))
- return true;
+ int amt = inputStream.read(byteBuffer);
+ if (amt == -1)
+ return false;
+ for (int i = 0; i < amt; i++)
+ {
+ if (dealWithByte(byteBuffer[i]))
+ return true;
+ }
}
- return false;
}
/** Receive a byte.
Modified:
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/SingleCharacterReceiver.java
URL:
http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/SingleCharacterReceiver.java?rev=1443879&r1=1443878&r2=1443879&view=diff
==============================================================================
---
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/SingleCharacterReceiver.java
(original)
+++
manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/SingleCharacterReceiver.java
Fri Feb 8 08:33:41 2013
@@ -34,22 +34,24 @@ public abstract class SingleCharacterRec
charBuffer = new char[chunkSize];
}
- /** Receive a set of characters; process one chunksize worth.
- *@return true if done.
+ /** Receive a stream of characters.
+ *@return true if abort signalled, false if end of stream.
*/
@Override
- public boolean dealWithCharacters()
+ public final boolean dealWithCharacters(Reader reader)
throws IOException, ManifoldCFException
{
- int amt = reader.read(charBuffer);
- if (amt == -1)
- return true;
- for (int i = 0; i < amt; i++)
+ while (true)
{
- if (dealWithCharacter(charBuffer[i]))
- return true;
+ int amt = reader.read(charBuffer);
+ if (amt == -1)
+ return false;
+ for (int i = 0; i < amt; i++)
+ {
+ if (dealWithCharacter(charBuffer[i]))
+ return true;
+ }
}
- return false;
}
/** Receive a byte.