本文整理汇总了Java中org.h2.util.IOUtils类的典型用法代码示例。如果您正苦于以下问题:Java IOUtils类的具体用法?Java IOUtils怎么用?Java IOUtils使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IOUtils类属于org.h2.util包,在下文中一共展示了IOUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: loadJSONFromResource
import org.h2.util.IOUtils; //导入依赖的package包/类
public static String loadJSONFromResource(String resname, ClassLoader loader) {
System.out.println("Loading local resource: " + resname);
try {
InputStreamReader reader = new InputStreamReader(loader.getResourceAsStream(resname));
StringWriter writer = new StringWriter();
IOUtils.copyAndCloseInput(reader, writer, 100000000);
writer.close();
return writer.toString();
} catch (IOException e) {
e.printStackTrace();
}
return "";
}
示例2: openWriter
import org.h2.util.IOUtils; //导入依赖的package包/类
private boolean openWriter() {
if (printWriter == null) {
try {
FileUtils.createDirectories(FileUtils.getParent(fileName));
if (FileUtils.exists(fileName) && !FileUtils.canWrite(fileName)) {
// read only database: don't log error if the trace file
// can't be opened
return false;
}
fileWriter = IOUtils.getBufferedWriter(
FileUtils.newOutputStream(fileName, true));
printWriter = new PrintWriter(fileWriter, true);
} catch (Exception e) {
logWritingError(e);
return false;
}
}
return true;
}
示例3: length
import org.h2.util.IOUtils; //导入依赖的package包/类
/**
* Returns the length.
*
* @return the length
*/
@Override
public long length() throws SQLException {
try {
debugCodeCall("length");
checkClosed();
if (value.getType() == Value.CLOB) {
long precision = value.getPrecision();
if (precision > 0) {
return precision;
}
}
return IOUtils.copyAndCloseInput(value.getReader(), null, Long.MAX_VALUE);
} catch (Exception e) {
throw logAndConvert(e);
}
}
示例4: setAsciiStream
import org.h2.util.IOUtils; //导入依赖的package包/类
/**
* Sets the value of a parameter as an ASCII stream.
* This method does not close the stream.
* The stream may be closed after executing the statement.
*
* @param parameterIndex the parameter index (1, 2, ...)
* @param x the value
* @param length the maximum number of bytes
* @throws SQLException if this object is closed
*/
@Override
public void setAsciiStream(int parameterIndex, InputStream x, long length)
throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("setAsciiStream("+parameterIndex+", x, "+length+"L);");
}
checkClosedForWrite();
try {
Value v = conn.createClob(IOUtils.getAsciiReader(x), length);
setParameter(parameterIndex, v);
} finally {
afterWriting();
}
} catch (Exception e) {
throw logAndConvert(e);
}
}
示例5: length
import org.h2.util.IOUtils; //导入依赖的package包/类
/**
* Returns the length.
*
* @return the length
*/
@Override
public long length() throws SQLException {
try {
debugCodeCall("length");
checkClosed();
if (value.getType() == Value.BLOB) {
long precision = value.getPrecision();
if (precision > 0) {
return precision;
}
}
return IOUtils.copyAndCloseInput(value.getInputStream(), null);
} catch (Exception e) {
throw logAndConvert(e);
}
}
示例6: getBytes
import org.h2.util.IOUtils; //导入依赖的package包/类
/**
* Returns some bytes of the object.
*
* @param pos the index, the first byte is at position 1
* @param length the number of bytes
* @return the bytes, at most length bytes
*/
@Override
public byte[] getBytes(long pos, int length) throws SQLException {
try {
if (isDebugEnabled()) {
debugCode("getBytes("+pos+", "+length+");");
}
checkClosed();
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStream in = value.getInputStream();
try {
IOUtils.skipFully(in, pos - 1);
IOUtils.copy(in, out, length);
} finally {
in.close();
}
return out.toByteArray();
} catch (Exception e) {
throw logAndConvert(e);
}
}
示例7: createFromReader
import org.h2.util.IOUtils; //导入依赖的package包/类
private void createFromReader(char[] buff, int len, Reader in,
long remaining, DataHandler h) throws IOException {
FileStoreOutputStream out = initLarge(h);
boolean compress = h.getLobCompressionAlgorithm(Value.CLOB) != null;
try {
while (true) {
precision += len;
byte[] b = new String(buff, 0, len).getBytes(Constants.UTF8);
out.write(b, 0, b.length);
remaining -= len;
if (remaining <= 0) {
break;
}
len = getBufferSize(h, compress, remaining);
len = IOUtils.readFully(in, buff, len);
if (len == 0) {
break;
}
}
} finally {
out.close();
}
}
示例8: createFromStream
import org.h2.util.IOUtils; //导入依赖的package包/类
private void createFromStream(byte[] buff, int len, InputStream in,
long remaining, DataHandler h) throws IOException {
FileStoreOutputStream out = initLarge(h);
boolean compress = h.getLobCompressionAlgorithm(Value.BLOB) != null;
try {
while (true) {
precision += len;
out.write(buff, 0, len);
remaining -= len;
if (remaining <= 0) {
break;
}
len = getBufferSize(h, compress, remaining);
len = IOUtils.readFully(in, buff, len);
if (len <= 0) {
break;
}
}
} finally {
out.close();
}
}
示例9: getString
import org.h2.util.IOUtils; //导入依赖的package包/类
@Override
public String getString() {
int len = precision > Integer.MAX_VALUE || precision == 0 ?
Integer.MAX_VALUE : (int) precision;
try {
if (type == Value.CLOB) {
if (small != null) {
return new String(small, Constants.UTF8);
}
return IOUtils.readStringAndClose(getReader(), len);
}
byte[] buff;
if (small != null) {
buff = small;
} else {
buff = IOUtils.readBytesAndClose(getInputStream(), len);
}
return StringUtils.convertBytesToHex(buff);
} catch (IOException e) {
throw DbException.convertIOException(e, fileName);
}
}
示例10: getBytesNoCopy
import org.h2.util.IOUtils; //导入依赖的package包/类
@Override
public byte[] getBytesNoCopy() {
if (type == CLOB) {
// convert hex to string
return super.getBytesNoCopy();
}
if (small != null) {
return small;
}
try {
return IOUtils.readBytesAndClose(
getInputStream(), Integer.MAX_VALUE);
} catch (IOException e) {
throw DbException.convertIOException(e, fileName);
}
}
示例11: getString
import org.h2.util.IOUtils; //导入依赖的package包/类
@Override
public String getString() {
int len = precision > Integer.MAX_VALUE || precision == 0 ?
Integer.MAX_VALUE : (int) precision;
try {
if (type == Value.CLOB) {
if (small != null) {
return new String(small, Constants.UTF8);
}
return IOUtils.readStringAndClose(getReader(), len);
}
byte[] buff;
if (small != null) {
buff = small;
} else {
buff = IOUtils.readBytesAndClose(getInputStream(), len);
}
return StringUtils.convertBytesToHex(buff);
} catch (IOException e) {
throw DbException.convertIOException(e, toString());
}
}
示例12: getFile
import org.h2.util.IOUtils; //导入依赖的package包/类
/**
* Read the given file from the file system or from the resources.
*
* @param file the file name
* @return the data
*/
byte[] getFile(String file) throws IOException {
trace("getFile <" + file + ">");
if (file.startsWith(TRANSFER + "/") && new File(TRANSFER).exists()) {
file = file.substring(TRANSFER.length() + 1);
if (!isSimpleName(file)) {
return null;
}
File f = new File(TRANSFER, file);
if (!f.exists()) {
return null;
}
return IOUtils.readBytesAndClose(new FileInputStream(f), -1);
}
byte[] data = Utils.getResource("/org/h2/server/web/res/" + file);
if (data == null) {
trace(" null");
} else {
trace(" size=" + data.length);
}
return data;
}
示例13: installPgCatalog
import org.h2.util.IOUtils; //导入依赖的package包/类
private static void installPgCatalog(Statement stat) throws SQLException {
Reader r = null;
try {
r = new InputStreamReader(new ByteArrayInputStream(Utils
.getResource("/org/h2/server/pg/pg_catalog.sql")));
ScriptReader reader = new ScriptReader(r);
while (true) {
String sql = reader.readStatement();
if (sql == null) {
break;
}
stat.execute(sql);
}
reader.close();
} catch (IOException e) {
throw DbException.convertIOException(e, "Can not read pg_catalog resource");
} finally {
IOUtils.closeSilently(r);
}
}
示例14: newOutputStream
import org.h2.util.IOUtils; //导入依赖的package包/类
@Override
public OutputStream newOutputStream(boolean append) throws IOException {
try {
File file = new File(name);
File parent = file.getParentFile();
if (parent != null) {
FileUtils.createDirectories(parent.getAbsolutePath());
}
FileOutputStream out = new FileOutputStream(name, append);
IOUtils.trace("openFileOutputStream", name, out);
return out;
} catch (IOException e) {
freeMemoryAndFinalize();
return new FileOutputStream(name);
}
}
示例15: open
import org.h2.util.IOUtils; //导入依赖的package包/类
@Override
public FileChannel open(String mode) throws IOException {
FileDisk f;
try {
f = new FileDisk(name, mode);
IOUtils.trace("open", name, f);
} catch (IOException e) {
freeMemoryAndFinalize();
try {
f = new FileDisk(name, mode);
} catch (IOException e2) {
throw e;
}
}
return f;
}