OSDir


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GitHub] stevedlawrence commented on a change in pull request #77: Modifications to IO layer to support streaming input data


stevedlawrence commented on a change in pull request #77: Modifications to IO layer to support streaming input data
URL: https://github.com/apache/incubator-daffodil/pull/77#discussion_r201096952
 
 

 ##########
 File path: daffodil-io/src/main/scala/org/apache/daffodil/processors/charset/BitsCharsetDecoder.scala
 ##########
 @@ -0,0 +1,198 @@
+/*
+ * 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.daffodil.processors.charset
+
+import java.nio.CharBuffer
+import java.nio.LongBuffer
+
+import org.apache.daffodil.exceptions.Assert
+import org.apache.daffodil.exceptions.ThinThrowable
+import org.apache.daffodil.io.InputSourceDataInputStream
+import org.apache.daffodil.io.DataInputStream.NotEnoughDataException
+import org.apache.daffodil.io.FormatInfo
+import org.apache.daffodil.schema.annotation.props.gen.EncodingErrorPolicy
+import org.apache.daffodil.util.MaybeChar
+
+
+class BitsCharsetDecoderMalformedException(val malformedBits: Int)
+  extends Exception with ThinThrowable
+
+trait BitsCharsetDecoderState
+
+abstract class BitsCharsetDecoder {
+
+  /**
+   * Decode a single character
+   *
+   * This should read data via the InputSourceDataInputStream in whatever manner is most
+   * efficient, as long as at the end of the decode the bitPosition0b is set to
+   * to end of the character.
+   *
+   * If there was a decode error, the bit position should be set to the end of
+   * malformed bits and a BitsCharsetDecoderMalformedException should be thrown
+   * specifying how many bits were malformed.
+   */
+  protected def decodeOneChar(dis: InputSourceDataInputStream, finfo: FormatInfo): Char
+
+  /**
+   * Decode multiple characters into a CharBuffer, keeping track of the
+   * bit positions after each Char decode
+   *
+   * Decodes at most chars.remaining() characters in the chars CharBuffer. If
+   * bitPositions is provided, for each decoded character the bitPosition0b
+   * where the character decode operation finished is stored in the
+   * bitPositions LongBuffer. Upon return of the decode operation, the
+   * bitPosition0b of the InputSourceDataInputStream will be the end of the last
+   * successful character decode operation. Returns the number of successfully
+   * decode characters.
+   */
+  final def decode(dis: InputSourceDataInputStream, finfo: FormatInfo, chars: CharBuffer, bitPositions: LongBuffer = null): Int = {
 
 Review comment:
   Absolutely agreed. I was hesitant at first, but the decoders really weren't too difficult to write and the resulting code was sooo much simpler.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@xxxxxxxxxxxxxxxx


With regards,
Apache Git Services