Following piece of codes demonstrate the process of doing the conversion.
.........
.........
Clob textClobValue;
String textValue;
String newTextValue;
Clob newTextClobValue;
InputStream textStream;
Paragraph paragraph // my domain Class that contains a clob datatypes and used to update the database connection with hibernate connection (Hibernate version >=3.0)
...........
...........
textClobValue=paragraph.getText();
textStream = textClobValue.getAsciiStream(); //return inputstream
textValue=convertStreamToString(textStream);
newTextValue=textValue.replaceAll("Some text","new Text"); //Replacing some text from old text.
newTextClobValue=Hibernate.createClob(newTextValue);
//System.out.println("Updated="+newParaContentValue);
paragraph.setText(newTextClobValue);
..........
..........
..........
public static String convertStreamToString(InputStream is) throws Exception {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
is.close();
return sb.toString();
}