本文整理汇总了Java中org.h2.util.IOUtils.copy方法的典型用法代码示例。如果您正苦于以下问题:Java IOUtils.copy方法的具体用法?Java IOUtils.copy怎么用?Java IOUtils.copy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.h2.util.IOUtils
的用法示例。
在下文中一共展示了IOUtils.copy方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: 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);
}
}
示例2: cat
import org.h2.util.IOUtils; //导入方法依赖的package包/类
private void cat(String fileName, long length) {
if (!FileUtils.exists(fileName)) {
print("No such file: " + fileName);
}
if (FileUtils.isDirectory(fileName)) {
print("Is a directory: " + fileName);
}
InputStream inFile = null;
try {
inFile = FileUtils.newInputStream(fileName);
IOUtils.copy(inFile, out, length);
} catch (IOException e) {
error(e);
} finally {
IOUtils.closeSilently(inFile);
}
println("");
}
示例3: uploadMultipart
import org.h2.util.IOUtils; //导入方法依赖的package包/类
private void uploadMultipart(InputStream in, int len) throws IOException {
if (!new File(WebServer.TRANSFER).exists()) {
return;
}
String fileName = "temp.bin";
headerBytes = 0;
String boundary = readHeaderLine();
while (true) {
String line = readHeaderLine();
if (line == null) {
break;
}
int index = line.indexOf("filename=\"");
if (index > 0) {
fileName = line.substring(index +
"filename=\"".length(), line.lastIndexOf('"'));
}
trace(" " + line);
}
if (!WebServer.isSimpleName(fileName)) {
return;
}
len -= headerBytes;
File file = new File(WebServer.TRANSFER, fileName);
OutputStream out = new FileOutputStream(file);
IOUtils.copy(in, out, len);
out.close();
// remove the boundary
RandomAccessFile f = new RandomAccessFile(file, "rw");
int testSize = (int) Math.min(f.length(), Constants.IO_BUFFER_SIZE);
f.seek(f.length() - testSize);
byte[] bytes = DataUtils.newBytes(Constants.IO_BUFFER_SIZE);
f.readFully(bytes, 0, testSize);
String s = new String(bytes, "ASCII");
int x = s.lastIndexOf(boundary);
f.setLength(f.length() - testSize + x - 2);
f.close();
}
示例4: receive
import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
* Read a file from a client.
*
* @param fileName the target file name
*/
synchronized void receive(String fileName) throws IOException {
connect();
try {
InputStream in = socket.getInputStream();
OutputStream out = FileUtils.newOutputStream(fileName, false);
IOUtils.copy(in, out);
out.close();
} finally {
socket.close();
}
server.trace("closed");
}
示例5: send
import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
* Send a file to the client. This method waits until the client has
* connected.
*
* @param fileName the source file name
* @param skip the number of bytes to skip
*/
synchronized void send(String fileName, long skip) throws IOException {
connect();
try {
OutputStream out = socket.getOutputStream();
InputStream in = FileUtils.newInputStream(fileName);
IOUtils.skipFully(in, skip);
IOUtils.copy(in, out);
in.close();
} finally {
socket.close();
}
server.trace("closed");
}
示例6: unzip
import org.h2.util.IOUtils; //导入方法依赖的package包/类
private void unzip(String zipFileName, String targetDir) {
InputStream inFile = null;
try {
inFile = FileUtils.newInputStream(zipFileName);
ZipInputStream zipIn = new ZipInputStream(inFile);
while (true) {
ZipEntry entry = zipIn.getNextEntry();
if (entry == null) {
break;
}
String fileName = entry.getName();
// restoring windows backups on linux and vice versa
fileName = fileName.replace('\\',
SysProperties.FILE_SEPARATOR.charAt(0));
fileName = fileName.replace('/',
SysProperties.FILE_SEPARATOR.charAt(0));
if (fileName.startsWith(SysProperties.FILE_SEPARATOR)) {
fileName = fileName.substring(1);
}
OutputStream o = null;
try {
o = FileUtils.newOutputStream(targetDir
+ SysProperties.FILE_SEPARATOR + fileName, false);
IOUtils.copy(zipIn, o);
o.close();
} finally {
IOUtils.closeSilently(o);
}
zipIn.closeEntry();
}
zipIn.closeEntry();
zipIn.close();
} catch (IOException e) {
error(e);
} finally {
IOUtils.closeSilently(inFile);
}
}
示例7: execute
import org.h2.util.IOUtils; //导入方法依赖的package包/类
/**
* Restores database files.
*
* @param zipFileName the name of the backup file
* @param directory the directory name
* @param db the database name (null for all databases)
* @throws DbException if there is an IOException
*/
public static void execute(String zipFileName, String directory, String db) {
InputStream in = null;
try {
if (!FileUtils.exists(zipFileName)) {
throw new IOException("File not found: " + zipFileName);
}
String originalDbName = null;
int originalDbLen = 0;
if (db != null) {
originalDbName = getOriginalDbName(zipFileName, db);
if (originalDbName == null) {
throw new IOException("No database named " + db + " found");
}
if (originalDbName.startsWith(SysProperties.FILE_SEPARATOR)) {
originalDbName = originalDbName.substring(1);
}
originalDbLen = originalDbName.length();
}
in = FileUtils.newInputStream(zipFileName);
ZipInputStream zipIn = new ZipInputStream(in);
while (true) {
ZipEntry entry = zipIn.getNextEntry();
if (entry == null) {
break;
}
String fileName = entry.getName();
// restoring windows backups on linux and vice versa
fileName = fileName.replace('\\', SysProperties.FILE_SEPARATOR.charAt(0));
fileName = fileName.replace('/', SysProperties.FILE_SEPARATOR.charAt(0));
if (fileName.startsWith(SysProperties.FILE_SEPARATOR)) {
fileName = fileName.substring(1);
}
boolean copy = false;
if (db == null) {
copy = true;
} else if (fileName.startsWith(originalDbName + ".")) {
fileName = db + fileName.substring(originalDbLen);
copy = true;
}
if (copy) {
OutputStream o = null;
try {
o = FileUtils.newOutputStream(
directory + SysProperties.FILE_SEPARATOR + fileName, false);
IOUtils.copy(zipIn, o);
o.close();
} finally {
IOUtils.closeSilently(o);
}
}
zipIn.closeEntry();
}
zipIn.closeEntry();
zipIn.close();
} catch (IOException e) {
throw DbException.convertIOException(e, zipFileName);
} finally {
IOUtils.closeSilently(in);
}
}
示例8: test
import org.h2.util.IOUtils; //导入方法依赖的package包/类
private void test(StreamStore store, int minBlockSize, int maxBlockSize,
int length) throws IOException {
store.setMinBlockSize(minBlockSize);
assertEquals(minBlockSize, store.getMinBlockSize());
store.setMaxBlockSize(maxBlockSize);
assertEquals(maxBlockSize, store.getMaxBlockSize());
long next = store.getNextKey();
Random r = new Random(length);
byte[] data = new byte[length];
r.nextBytes(data);
byte[] id = store.put(new ByteArrayInputStream(data));
if (length > 0 && length >= minBlockSize) {
assertFalse(store.isInPlace(id));
} else {
assertTrue(store.isInPlace(id));
}
long next2 = store.getNextKey();
if (length > 0 && length >= minBlockSize) {
assertTrue(next2 > next);
} else {
assertEquals(next, next2);
}
if (length == 0) {
assertEquals(0, id.length);
}
assertEquals(length, store.length(id));
InputStream in = store.get(id);
ByteArrayOutputStream out = new ByteArrayOutputStream();
IOUtils.copy(in, out);
assertTrue(Arrays.equals(data, out.toByteArray()));
in = store.get(id);
in.close();
assertEquals(-1, in.read());
in = store.get(id);
assertEquals(0, in.skip(0));
if (length > 0) {
assertEquals(1, in.skip(1));
if (length > 1) {
assertEquals(data[1] & 255, in.read());
if (length > 2) {
assertEquals(1, in.skip(1));
if (length > 3) {
assertEquals(data[3] & 255, in.read());
}
} else {
assertEquals(0, in.skip(1));
}
} else {
assertEquals(-1, in.read());
}
} else {
assertEquals(0, in.skip(1));
}
if (length > 12) {
in = store.get(id);
assertEquals(12, in.skip(12));
assertEquals(data[12] & 255, in.read());
long skipped = 0;
while (true) {
long s = in.skip(Integer.MAX_VALUE);
if (s == 0) {
break;
}
skipped += s;
}
assertEquals(length - 13, skipped);
assertEquals(-1, in.read());
}
store.remove(id);
assertEquals(0, store.getMap().size());
}