Package java.io

Examples of java.io.InputStream


        }
       
        if (msg != null) {
          httpConn.setDoOutput(true);
          OutputStream os = httpConn.getOutputStream();
          InputStream is = msg.getInputStream();
          ObjectConverterUtil.write(os, is, -1);
        }
       
        return new HttpDataSource(url, httpConn);
      } catch (IOException e) {
View Full Code Here


            return;
        }
        deleteDb("scriptSimple");
        reconnect();
        String inFile = "org/h2/test/testSimple.in.txt";
        InputStream is = getClass().getClassLoader().getResourceAsStream(inFile);
        LineNumberReader lineReader = new LineNumberReader(new InputStreamReader(is, "Cp1252"));
        ScriptReader reader = new ScriptReader(lineReader);
        while (true) {
            String sql = reader.readStatement();
            if (sql == null) {
                break;
            }
            sql = sql.trim();
            try {
                if ("@reconnect".equals(sql.toLowerCase())) {
                    reconnect();
                } else if (sql.length() == 0) {
                    // ignore
                } else if (sql.toLowerCase().startsWith("select")) {
                    ResultSet rs = conn.createStatement().executeQuery(sql);
                    while (rs.next()) {
                        String expected = reader.readStatement().trim();
                        String got = "> " + rs.getString(1);
                        assertEquals(sql, expected, got);
                    }
                } else {
                    conn.createStatement().execute(sql);
                }
            } catch (SQLException e) {
                System.out.println(sql);
                throw e;
            }
        }
        is.close();
        conn.close();
        deleteDb("scriptSimple");
    }
View Full Code Here

            throw new SQLException(CorePlugin.Util.getString("MMClob_MMBlob.3", params)); //$NON-NLS-1$
        }
        else if (pos + length > length()) {
            length = (int)(length() - pos);
        }
        InputStream in = getBinaryStream();
        try {
          long skipped = 0;
          while (pos > 0) {
            skipped = in.skip(pos);
            pos -= skipped;
          }
          return ObjectConverterUtil.convertToByteArray(in, length);
        } catch (IOException e) {
          throw new SQLException(e);
        } finally {
          try {
        in.close();
      } catch (IOException e) {
      }
        }
    }
View Full Code Here

     * designated by this <code>Blob</code> object.
     * @return length of the <code>BLOB</code> in bytes
     */
    public long length() throws SQLException{
      if (getStreamFactory().getLength() == -1) {
        InputStream is = new BufferedInputStream(getBinaryStream());
      try {
          long length = 0;
          while (is.read() != -1) {
            length++;
          }
        getStreamFactory().setLength(length);
      } catch (IOException e) {
        throw new SQLException(e);
      } finally {
        try {
          is.close();
        } catch (IOException e) {
        }
      }
      }
        return getStreamFactory().getLength();
View Full Code Here

    private static final int DEFAULT_READING_SIZE = 8192;

     protected static byte[] convertBlobToByteArray(final java.sql.Blob data) throws TeiidException {
          try {
              // Open a stream to read the BLOB data
              InputStream l_blobStream = data.getBinaryStream();
              return convertToByteArray(l_blobStream);
          } catch (IOException ioe) {
                final Object[] params = new Object[]{data.getClass().getName()};
                throw new TeiidException(ioe,CorePlugin.Util.getString("ObjectConverterUtil.Error_translating_results_from_data_type_to_a_byte[]._1",params)); //$NON-NLS-1$
          } catch (SQLException sqe) {
View Full Code Here

        }
    }

    public static InputStream convertToInputStream(byte[] data) {
        ByteArrayInputStream bais = new ByteArrayInputStream(data);
        InputStream isContent = new BufferedInputStream(bais);
        return isContent;
    }
View Full Code Here

        BufferedOutputStream bos = new BufferedOutputStream(fio);
      write(bos, is, -1);
    }
   
    public static void write(byte[] data, final String fileName) throws Exception {
        InputStream is = ObjectConverterUtil.convertToInputStream(data);
        ObjectConverterUtil.write(is, fileName);
        is.close();
    }
View Full Code Here

        ObjectConverterUtil.write(is, fileName);
        is.close();
    }
   
    public static void write(char[] data, final String fileName) throws Exception {
        InputStream is = ObjectConverterUtil.convertToInputStream(data);
        ObjectConverterUtil.write(is, fileName);
        is.close();
    }
View Full Code Here

     * Returns the contents of the given file as a char array.
     * When encoding is null, then the platform default one is used
     * @throws IOException if a problem occurred reading the file.
     */
    public static char[] convertFileToCharArray(File file, String encoding) throws IOException {
        InputStream stream = new FileInputStream(file);
        return convertToCharArray(stream, (int) file.length(), encoding);
    }
View Full Code Here

         * Use karp-rabin matching to reduce the cost of back tracing for failed matches
         *
         * TODO: optimize for patterns that are small enough to fit in a reasonable buffer
         */
        try {
          InputStream patternStream = pattern.getBinaryStream();
          InputStream targetStream = target.getBinaryStream();
          InputStream laggingTargetStream = target.getBinaryStream();
          try {
            int patternHash = computeStreamHash(patternStream, patternLength);
            int lastMod = 1;
            for (int i = 0; i < patternLength; i++) {
              lastMod *= MOD;
            }             
            targetStream.skip(start);
            laggingTargetStream.skip(start);
           
            long position = start + 1;
           
            int streamHash = computeStreamHash(targetStream, patternLength);
           
            do {
              if ((position -1)%bytesPerComparison == 0 && patternHash == streamHash && validateMatch(pattern, target, position)) {
                return (position - 1)/bytesPerComparison + 1;
              }
             
              streamHash = MOD * streamHash + targetStream.read() - lastMod * laggingTargetStream.read();
              position++;
           
            } while (position + patternLength - 1 <= targetLength);
           
            return -1;
          } finally {
            if (patternStream != null) {
              patternStream.close();
            }
            if (targetStream != null) {
              targetStream.close();
            }
            if (laggingTargetStream != null) {
              laggingTargetStream.close();
            }
          }
        } catch (IOException e) {
          throw new SQLException(e);
        }
View Full Code Here

TOP

Related Classes of java.io.InputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.