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 20:23:23 UTC

svn commit: r1443150 - in /manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml: ByteBuffer.java PrefixedInputStream.java PretagParseState.java

Author: kwright
Date: Wed Feb  6 19:23:23 2013
New Revision: 1443150

URL: http://svn.apache.org/viewvc?rev=1443150&view=rev
Log:
Add prefixed input stream.

Added:
    manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/ByteBuffer.java   (with props)
    manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/PrefixedInputStream.java   (with props)
Modified:
    manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/PretagParseState.java

Added: 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=1443150&view=auto
==============================================================================
--- manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/ByteBuffer.java (added)
+++ manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/ByteBuffer.java Wed Feb  6 19:23:23 2013
@@ -0,0 +1,64 @@
+/* $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.*;
+
+/** This class represents a variable-length buffer for bytes.
+*/
+public class ByteBuffer
+{
+  // MHL
+  
+  /** Constructor */
+  public ByteBuffer()
+  {
+  }
+  
+  /** Clear the buffer.
+  */
+  public void clear()
+  {
+    // MHL
+  }
+  
+  /** Get the current buffer length.
+  */
+  public int size()
+  {
+    // MHL
+    return 0;
+  }
+  
+  /** Add a byte to the buffer at the end.
+  */
+  public void appendByte(byte b)
+  {
+    // MHL
+  }
+  
+  /** Read a byte from the buffer from the specified place.
+  */
+  public byte readByte(int position)
+  {
+    // MHL
+    return (byte)0;
+  }
+  
+}

Propchange: manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/ByteBuffer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/ByteBuffer.java
------------------------------------------------------------------------------
    svn:keywords = Id

Added: manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/PrefixedInputStream.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/PrefixedInputStream.java?rev=1443150&view=auto
==============================================================================
--- manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/PrefixedInputStream.java (added)
+++ manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/PrefixedInputStream.java Wed Feb  6 19:23:23 2013
@@ -0,0 +1,83 @@
+/* $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.*;
+
+/** This class represents an input stream that begins with bytes
+* passed to it through the constructor, and then continues with the bytes
+* from a wrapped input stream.  It's basically used when
+* we've read past where we want to be in an input stream and need to back up.
+*/
+public class PrefixedInputStream extends InputStream
+{
+  protected final ByteBuffer bytes;
+  protected final InputStream remainderStream;
+  
+  protected int bytePosition = 0;
+  protected int byteMax;
+  
+  /** Constructor */
+  public PrefixedInputStream(ByteBuffer bytes, InputStream remainderStream)
+  {
+    this.bytes = bytes;
+    this.remainderStream = remainderStream;
+    byteMax = bytes.size();
+  }
+
+  @Override
+  public int read()
+    throws IOException
+  {
+    if (bytePosition < byteMax)
+      return 0xff & (int)bytes.readByte(bytePosition++);
+    return remainderStream.read();
+  }
+  
+  @Override
+  public int read(byte[] b, int off, int len)
+    throws IOException
+  {
+    // Use the superclass method that goes through read, if we're within the
+    // buffer.
+    if (bytePosition < byteMax)
+      return super.read(b,off,len);
+    // Outside of the local buffer, vector right through to the remainder stream.
+    return remainderStream.read(b,off,len);
+  }
+  
+  @Override
+  public long skip(long n)
+    throws IOException
+  {
+    if (bytePosition < byteMax)
+      return super.skip(n);
+    return remainderStream.skip(n);
+  }
+  
+  @Override
+  public void close()
+    throws IOException
+  {
+    // Since the wrapped input stream 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/PrefixedInputStream.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/PrefixedInputStream.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/PretagParseState.java
URL: http://svn.apache.org/viewvc/manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/PretagParseState.java?rev=1443150&r1=1443149&r2=1443150&view=diff
==============================================================================
--- manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/PretagParseState.java (original)
+++ manifoldcf/branches/CONNECTORS-633/framework/core/src/main/java/org/apache/manifoldcf/core/fuzzyml/PretagParseState.java Wed Feb  6 19:23:23 2013
@@ -28,6 +28,39 @@ public class PretagParseState extends Si
 {
   protected final CharacterReceiver postPreambleReceiver;
 
+  protected static final int PRETAGPARSESTATE_NORMAL = 0;
+  protected static final int PRETAGPARSESTATE_SAWLEFTBRACKET = 1;
+  protected static final int PRETAGPARSESTATE_SAWEXCLAMATION = 2;
+  protected static final int PRETAGPARSESTATE_SAWQUESTION = 3;
+  protected static final int PRETAGPARSESTATE_IN_TAG_SAW_QUESTION = 4;
+  protected static final int PRETAGPARSESTATE_IN_TAG_NAME = 7;
+  protected static final int PRETAGPARSESTATE_IN_ATTR_NAME = 8;
+  protected static final int PRETAGPARSESTATE_IN_ATTR_VALUE = 9;
+  protected static final int PRETAGPARSESTATE_IN_ATTR_LOOKING_FOR_VALUE = 12;
+  protected static final int PRETAGPARSESTATE_IN_SINGLE_QUOTES_ATTR_VALUE = 13;
+  protected static final int PRETAGPARSESTATE_IN_DOUBLE_QUOTES_ATTR_VALUE = 14;
+  protected static final int PRETAGPARSESTATE_POST = 15;
+
+  protected int currentState = PRETAGPARSESTATE_NORMAL;
+
+  protected StringBuilder currentTagNameBuffer = null;
+  protected StringBuilder currentAttrNameBuffer = null;
+  protected StringBuilder currentValueBuffer = null;
+
+  protected String currentTagName = null;
+  protected String currentAttrName = null;
+  protected Map<String,String> currentAttrMap = null;
+
+  protected static final Map<String,String> mapLookup = new HashMap<String,String>();
+  static
+  {
+    mapLookup.put("amp","&");
+    mapLookup.put("lt","<");
+    mapLookup.put("gt",">");
+    mapLookup.put("quot","\"");
+    mapLookup.put("apos","'");
+  }
+
   /** Constructor.  Pass in the post-preamble character receiver.
   * 
   */