Adding JMCR-Stable version
[Benchmarks_CSolver.git] / JMCR-Stable / real-world application / derby-10.3.2.1 / java / engine / org / apache / derby / impl / load / ImportBlob.java
diff --git a/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/load/ImportBlob.java b/JMCR-Stable/real-world application/derby-10.3.2.1/java/engine/org/apache/derby/impl/load/ImportBlob.java
new file mode 100644 (file)
index 0000000..ec5d508
--- /dev/null
@@ -0,0 +1,211 @@
+/*\r
+\r
+   Derby - Class org.apache.derby.impl.load.ImportBlob\r
+\r
+   Licensed to the Apache Software Foundation (ASF) under one or more\r
+   contributor license agreements.  See the NOTICE file distributed with\r
+   this work for additional information regarding copyright ownership.\r
+   The ASF licenses this file to You under the Apache License, Version 2.0\r
+   (the "License"); you may not use this file except in compliance with\r
+   the License.  You may obtain a copy of the License at\r
+\r
+      http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+   Unless required by applicable law or agreed to in writing, software\r
+   distributed under the License is distributed on an "AS IS" BASIS,\r
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+   See the License for the specific language governing permissions and\r
+   limitations under the License.\r
+\r
+ */\r
+\r
+package org.apache.derby.impl.load;\r
+import org.apache.derby.iapi.services.io.LimitInputStream;\r
+import org.apache.derby.iapi.util.StringUtil;\r
+import java.sql.Blob;\r
+import java.sql.SQLException;\r
+import java.io.InputStream;\r
+\r
+/**\r
+ * This class implements  <code > java.sql.BLOB interface </code>.  \r
+ * Objects created using the <code> ImportBlob </code> class  are \r
+ * intended to be be used to create a blob object of the data  stored \r
+ * in an import file or as an hex string.  Only the routines that \r
+ * are needed read the blob data for the blob columns by the \r
+ * inserts done through the VTI  have real implementations, \r
+ * Other routines are dummy ones to satisfy <code> java.sql.Blob </code> \r
+ * interface.\r
+ */\r
+\r
+class ImportBlob implements java.sql.Blob {\r
+\r
+    private ImportLobFile lobFile;\r
+       private long blobPosition;\r
+       private long blobLength;\r
+    private byte[] blobData = null;\r
+\r
+\r
+    /**\r
+     * Create a import Blob object, that reads <code> length </code> amount of \r
+     * data  from an external file, starting at <code> position </code>. \r
+     * @param lobFile  lob file resource object, using which data is read.\r
+     * @param position  byte offset in the file, of this blob columb data. \r
+     * @param length   length of this blob object data. \r
+     */\r
+    public ImportBlob(ImportLobFile lobFile, long position, long length) \r
+       {\r
+               this.lobFile = lobFile;\r
+               this.blobPosition = position;\r
+               this.blobLength = length;\r
+       }\r
+\r
+\r
+    /**\r
+     * Create a import Blob object, whose value is the give hex data string.  \r
+     * @param data  byte array that contains the blob data. \r
+     */\r
+    public ImportBlob(byte[] data) \r
+    {\r
+        blobData = data;\r
+        blobLength = data.length;\r
+    }\r
+\r
+\r
+  /**\r
+   * Returns the number of bytes in this <code>BLOB</code>  object.\r
+   * @return length of the <code>BLOB</code> in bytes\r
+   * @exception SQLException on any error.\r
+   */\r
+       public long length() throws SQLException {\r
+               return blobLength;\r
+       }\r
+\r
+\r
+    /**\r
+     * Returns  <code>BLOB</code> value designated by this\r
+     * <code>Blob</code> object as a input stream.\r
+     *\r
+     * @return a stream containing the <code>BLOB</code> data\r
+     * @exception SQLException if any error occurs while setting up \r
+     *                         this blob data in the import file as stream. \r
+     */\r
+       public java.io.InputStream getBinaryStream () throws SQLException\r
+       {\r
+               try {\r
+            InputStream fis;\r
+            if(blobData != null) {\r
+                fis = new java.io.ByteArrayInputStream(blobData);\r
+                // wrap the InputStream with a LimitInputStream class,\r
+                // only the length of the  \r
+                LimitInputStream  limitIn = new  LimitInputStream(fis);\r
+                limitIn.setLimit((int) blobLength);\r
+                return limitIn;\r
+\r
+            } else {\r
+                return lobFile.getBinaryStream(blobPosition, blobLength);\r
+            }\r
+               } catch (Exception e) {\r
+                       throw LoadError.unexpectedError(e);\r
+               }\r
+       }\r
+\r
+    \r
+    /** following rotines does not have implmentation because there are not\r
+     * used by the VTI that is used to import the data. \r
+     */\r
+\r
+    /**\r
+     * This routine is not used by the VTI to read the data, so no \r
+     * implementatio  is provided , an exception is thrown if used.  \r
+     *\r
+     * @see java.sql.Blob \r
+     */\r
+       public byte[] getBytes(long pos, int length) throws SQLException {\r
+               throw LoadError.unexpectedError(\r
+                         new Exception("Method not implemented"));\r
+       }\r
+\r
+    /**\r
+     * This routine is not used by the VTI to read the data, so no \r
+     * implementatio  is provided , an exception is thrown if used.  \r
+     *\r
+     * @see java.sql.Blob \r
+     */\r
+       public long position(byte pattern[], long start) throws SQLException\r
+       {\r
+               throw LoadError.unexpectedError(\r
+                        new Exception("Method not implemented"));\r
+       }\r
+\r
+    /**\r
+     * This routine is not used by the VTI to read the data, so no \r
+     * implementation is provided , an exception is thrown if used.  \r
+     *\r
+     * @see java.sql.Blob\r
+     */\r
+       public long position(Blob pattern, long start) throws SQLException {\r
+               throw LoadError.unexpectedError(\r
+                            new Exception("Method not implemented"));\r
+       }\r
+\r
+\r
+    /**\r
+     * This routine is not used by the VTI to read the data, so no \r
+     * implementation  is provided , an exception is thrown if used.  \r
+     *\r
+     * @see java.sql.Blob\r
+     */\r
+    public int setBytes(long pos, byte[] bytes) throws SQLException {\r
+               throw LoadError.unexpectedError(new Exception("Method not implemented"));\r
+       }\r
+\r
+    /**\r
+     * This routine is not used by the VTI to read the data, so no \r
+     * implementation  is provided , an exception is thrown if used.  \r
+     *\r
+     * @see java.sql.Blob\r
+     */\r
+    public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException\r
+       {\r
+               throw LoadError.unexpectedError(\r
+                        new Exception("Method not implemented"));\r
+       }\r
+\r
+    /**\r
+     * This routine is not used by the VTI to read the data, so no \r
+     * implementation  is provided , an exception is thrown if used.  \r
+     *\r
+     * @see java.sql.Blob\r
+     */\r
+    public java.io.OutputStream setBinaryStream(long pos) throws SQLException \r
+       {\r
+               throw LoadError.unexpectedError(\r
+                         new Exception("Method not implemented"));\r
+       }\r
+\r
+    /**\r
+     * This routine is not used by the VTI to read the data, so no \r
+     * implementation  is provided , an exception is thrown if used.  \r
+     *\r
+     * @see java.sql.Blob\r
+     */\r
+    public void truncate(long len) throws SQLException {\r
+               throw LoadError.unexpectedError(\r
+                        new Exception("Method not implemented"));\r
+       }\r
+\r
+\r
+       public void free() throws SQLException {\r
+               // TODO Auto-generated method stub\r
+               \r
+       }\r
+\r
+\r
+       public InputStream getBinaryStream(long pos, long length)\r
+                       throws SQLException {\r
+               // TODO Auto-generated method stub\r
+               return null;\r
+       }\r
+}\r
+\r
+\r