📄 ioagent.java
字号:
/**
*
*/
package com.esri.solutions.jitk.datasources.ogc.wcs;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
/**
* @author vlad2928
*
*/
public class IOAgent {
private static final Logger _logger = LogManager.getLogger(IOAgent.class);
private static void closeStream(Closeable stream) {
try {
if(stream != null) {
stream.close();
}
} catch(IOException e) {
_logger.error("Can not close stream.", e);
}
}
public static byte[] readIntoByteArray(InputStream is) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buf = new byte[4096];
for(int n=0; (n = is.read(buf)) != -1; baos.write(buf, 0, n));
closeStream(is);
return baos.toByteArray();
}
public static byte[] readIntoByteArray(File file) throws IOException {
return readIntoByteArray(new FileInputStream(file));
}
public static void write(InputStream is, OutputStream os) throws IOException {
byte[] buf = new byte[4096];
for(int n=0; (n = is.read(buf)) != -1; os.write(buf, 0, n));
os.flush();
closeStream(is);
closeStream(os);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -