Example 6-3: Writing data from a character Reader into a CLOB

import java.sql.SQLException;
import oracle.sql.CLOB;
import java.io.*;

public class WriteCLOB {
  // Write the contents read from a Reader into a CLOB
  public static void fromReader( Reader in, CLOB theClob ) throws SQLException {
    // Open character output stream for writing to the CLOB
    Writer out = theClob.getCharacterOutputStream();
    // Read in chunks from the input and write to the output,
    // asking the CLOB for its optimal ChunkSize
    int chunk = theClob.getChunkSize();
    char[] buffer = new char[chunk];
    int length = -1;
    try {
      while ((length = in.read(buffer)) != -1) {
        out.write(buffer, 0, length);
      }
    // Close streams
    in.close();
    out.close();
    }
    catch (IOException iox) { }
  }
}