use of org.h2.value.lob.LobDataFile in project h2database by h2database.
the class ValueClob method createTemporary.
/**
* Create a CLOB in a temporary file.
*/
private static ValueClob createTemporary(DataHandler handler, Reader in, long remaining) throws IOException {
String fileName = ValueLob.createTempLobFileName(handler);
FileStore tempFile = handler.openFile(fileName, "rw", false);
tempFile.autoDelete();
long octetLength = 0L, charLength = 0L;
try (FileStoreOutputStream out = new FileStoreOutputStream(tempFile, null)) {
char[] buff = new char[Constants.IO_BUFFER_SIZE];
while (true) {
int len = ValueLob.getBufferSize(handler, remaining);
len = IOUtils.readFully(in, buff, len);
if (len == 0) {
break;
}
// TODO reduce memory allocation
byte[] data = new String(buff, 0, len).getBytes(StandardCharsets.UTF_8);
out.write(data);
octetLength += data.length;
charLength += len;
}
}
return new ValueClob(new LobDataFile(handler, fileName, tempFile), octetLength, charLength);
}
use of org.h2.value.lob.LobDataFile in project SpringStudy by myounghaklee.
the class ValueBlob method createTemporary.
/**
* Create a BLOB in a temporary file.
*/
private static ValueBlob createTemporary(DataHandler handler, byte[] buff, int len, InputStream in, long remaining) throws IOException {
String fileName = ValueLob.createTempLobFileName(handler);
FileStore tempFile = handler.openFile(fileName, "rw", false);
tempFile.autoDelete();
long tmpPrecision = 0;
try (FileStoreOutputStream out = new FileStoreOutputStream(tempFile, null)) {
while (true) {
tmpPrecision += len;
out.write(buff, 0, len);
remaining -= len;
if (remaining <= 0) {
break;
}
len = ValueLob.getBufferSize(handler, remaining);
len = IOUtils.readFully(in, buff, len);
if (len <= 0) {
break;
}
}
}
return new ValueBlob(new LobDataFile(handler, fileName, tempFile), tmpPrecision);
}
use of org.h2.value.lob.LobDataFile in project h2database by h2database.
the class ValueBlob method createTemporary.
/**
* Create a BLOB in a temporary file.
*/
private static ValueBlob createTemporary(DataHandler handler, byte[] buff, int len, InputStream in, long remaining) throws IOException {
String fileName = ValueLob.createTempLobFileName(handler);
FileStore tempFile = handler.openFile(fileName, "rw", false);
tempFile.autoDelete();
long tmpPrecision = 0;
try (FileStoreOutputStream out = new FileStoreOutputStream(tempFile, null)) {
while (true) {
tmpPrecision += len;
out.write(buff, 0, len);
remaining -= len;
if (remaining <= 0) {
break;
}
len = ValueLob.getBufferSize(handler, remaining);
len = IOUtils.readFully(in, buff, len);
if (len <= 0) {
break;
}
}
}
return new ValueBlob(new LobDataFile(handler, fileName, tempFile), tmpPrecision);
}
use of org.h2.value.lob.LobDataFile in project SpringStudy by myounghaklee.
the class ValueClob method createTemporary.
/**
* Create a CLOB in a temporary file.
*/
private static ValueClob createTemporary(DataHandler handler, Reader in, long remaining) throws IOException {
String fileName = ValueLob.createTempLobFileName(handler);
FileStore tempFile = handler.openFile(fileName, "rw", false);
tempFile.autoDelete();
long octetLength = 0L, charLength = 0L;
try (FileStoreOutputStream out = new FileStoreOutputStream(tempFile, null)) {
char[] buff = new char[Constants.IO_BUFFER_SIZE];
while (true) {
int len = ValueLob.getBufferSize(handler, remaining);
len = IOUtils.readFully(in, buff, len);
if (len == 0) {
break;
}
// TODO reduce memory allocation
byte[] data = new String(buff, 0, len).getBytes(StandardCharsets.UTF_8);
out.write(data);
octetLength += data.length;
charLength += len;
}
}
return new ValueClob(new LobDataFile(handler, fileName, tempFile), octetLength, charLength);
}
Aggregations