long pre, long post, int mode)
throws IOException, SQLException {
long total = 0;
switch (mode) {
case SET_STRING: {
Reader charIn = new LoopingAlphabetReader(pre);
total += transferData(charIn, TRANSFER_BUFFER_SIZE);
this.clob.setString(pre +1, token);
total += token.length();
charIn = new LoopingAlphabetReader(post);
total += transferData(charIn, TRANSFER_BUFFER_SIZE);
break;
} case SET_ASCII_STREAM: {
OutputStream asciiOut = this.clob.setAsciiStream(1L);
InputStream asciiIn = new LoopingAlphabetStream(pre);
total += transferData(asciiIn, asciiOut, TRANSFER_BUFFER_SIZE);
byte[] tokenBytes = token.getBytes("ISO-8859-1");
asciiOut.write(tokenBytes, 0, tokenBytes.length);
total += tokenBytes.length;
asciiIn = new LoopingAlphabetStream(post);
total += transferData(asciiIn, asciiOut, TRANSFER_BUFFER_SIZE);
break;
} case SET_CHARACTER_STREAM: {
Writer charOut = this.clob.setCharacterStream(1L);
Reader charIn = new LoopingAlphabetReader(pre);
total += transferData(charIn, charOut, TRANSFER_BUFFER_SIZE);
charOut.write(token);
total += token.length();
charIn = new LoopingAlphabetReader(post);
total += transferData(charIn, charOut, TRANSFER_BUFFER_SIZE);
break;
} default:
throw new IllegalArgumentException(
"Unknown insertion mode: " + mode);