Ejemplo n.º 1
0
  /**
   * Test that <code>Clob.getCharacterStream(long,long)</code> works on CLOBs that are streamed from
   * store. (DERBY-2891)
   */
  public void testGetCharacterStreamLongOnLargeClob() throws Exception {
    getConnection().setAutoCommit(false);

    // create large (>32k) clob that can be read from store
    final int size = 33000;
    StringBuilder sb = new StringBuilder(size);
    for (int i = 0; i < size; i += 10) {
      sb.append("1234567890");
    }

    final int id = BlobClobTestSetup.getID();
    PreparedStatement ps =
        prepareStatement("insert into blobclob(id, clobdata) values (?,cast(? as clob))");
    ps.setInt(1, id);
    ps.setString(2, sb.toString());
    ps.executeUpdate();
    ps.close();

    Statement s = createStatement();
    ResultSet rs = s.executeQuery("select clobdata from blobclob where id = " + id);
    assertTrue(rs.next());
    Clob c = rs.getClob(1);

    // request a small region of the clob
    BufferedReader r = new BufferedReader(c.getCharacterStream(4L, 3L));
    assertEquals("456", r.readLine());

    r.close();
    c.free();
    rs.close();
    s.close();
    rollback();
  }
Ejemplo n.º 2
0
 private Object[] getTestData() throws IOException {
   InputStream in = getClass().getResourceAsStream("words.txt");
   BufferedReader r = new BufferedReader(new InputStreamReader(in));
   List list = new ArrayList();
   String line;
   int c = 0;
   while ((line = r.readLine()) != null) {
     list.add(line);
     if (c++ == 20) break;
   }
   return list.toArray();
 }
  /**
   * Returns the next non-comment, non-whitespace line of the input buffer.
   *
   * @param input the input buffer
   * @return the next non-comment, non-whitespace line of the input buffer or null if the end of the
   *     buffer is reached before such a line can be found
   */
  static /*@Nullable*/ String getNextRealLine(BufferedReader input) {
    String currentLine = "";

    try {
      while (currentLine != null) {
        currentLine = input.readLine();
        if (currentLine != null && !isComment(currentLine) && !isWhitespace(currentLine))
          return currentLine;
      }
    } catch (IOException e) {
      throw new RuntimeException(e.toString());
    }
    return null;
  }
Ejemplo n.º 4
0
  protected void compareFiles(File expected, File actual) throws IOException {
    if (!expected.exists()) {
      fail("Expected file " + expected + " does not exist.");
    }
    if (!actual.exists()) {
      fail("Output file " + actual + " does not exist.");
    }

    BufferedReader ebr = new BufferedReader(new FileReader(expected));
    BufferedReader abr = new BufferedReader(new FileReader(actual));
    String eline = null;
    String aline = null;
    int count = 0;
    try {
      while ((eline = ebr.readLine()) != null) {
        count++;
        aline = abr.readLine();

        if (aline == null) {
          fail(
              expected.getName()
                  + " "
                  + count
                  + ": No more lines in the output file "
                  + actual.getName());
        }

        assertEquals(
            "Lines from " + expected.getName() + " and " + actual.getName() + " are not the same",
            eline,
            aline);
      }

      if ((aline = abr.readLine()) != null) {
        fail(
            actual.getName()
                + " "
                + (count + 1)
                + ": No more lines in the expected file "
                + expected.getName());
      }

    } finally {
      ebr.close();
      abr.close();
    }
  }