use of java.io.BufferedOutputStream in project translationstudio8 by heartsome.
the class TMXValidator method save.
private boolean save(XMLModifier xm, File file) {
try {
FileOutputStream fos = new FileOutputStream(file);
BufferedOutputStream bos = new BufferedOutputStream(fos);
// 写入文件
xm.output(bos);
bos.close();
fos.close();
return true;
} catch (Exception e) {
LOGGER.error("", e);
}
return false;
}
use of java.io.BufferedOutputStream in project translationstudio8 by heartsome.
the class TSFileHandler method saveFile.
@Override
public Map<String, Object> saveFile(File srcFile, File tgtFile) {
if (srcFile == null || !srcFile.exists()) {
String msg = MessageFormat.format(Messages.getString("file.TSFileHandler.logger16"), srcFile.getAbsoluteFile());
logger.error(msg);
return getErrorResult(msg, null);
}
if (tgtFile == null || !tgtFile.exists()) {
String msg = MessageFormat.format(Messages.getString("file.TSFileHandler.logger17"), tgtFile.getAbsoluteFile());
logger.error(msg);
return getErrorResult(msg, null);
}
FileInputStream fis = null;
BufferedInputStream bis = null;
try {
fis = new FileInputStream(srcFile);
bis = new BufferedInputStream(fis);
} catch (FileNotFoundException e) {
String msg = MessageFormat.format(Messages.getString("file.TSFileHandler.logger16"), srcFile.getAbsoluteFile());
logger.error(msg, e);
return getErrorResult(msg, e);
}
FileOutputStream fos = null;
BufferedOutputStream bos = null;
try {
fos = new FileOutputStream(tgtFile);
bos = new BufferedOutputStream(fos);
} catch (FileNotFoundException e) {
String msg = MessageFormat.format(Messages.getString("file.TSFileHandler.logger17"), tgtFile.getAbsoluteFile());
logger.error(msg, e);
return getErrorResult(msg, e);
}
byte[] buffer = new byte[2048];
try {
while (bis.read(buffer) != -1) {
bos.write(buffer, 0, buffer.length);
}
bos.flush();
bos.close();
bis.close();
fos.close();
fis.close();
} catch (IOException e) {
String msg = null;
if (srcFile.getAbsolutePath().equals(tgtFile.getAbsolutePath())) {
msg = MessageFormat.format(Messages.getString("file.TSFileHandler.logger18"), srcFile.getAbsolutePath());
} else {
msg = MessageFormat.format(Messages.getString("file.TSFileHandler.logger19"), new Object[] { srcFile.getAbsolutePath(), tgtFile.getAbsolutePath() });
}
logger.error(msg, e);
return getErrorResult(msg, e);
}
return getSuccessResult(Messages.getString("file.TSFileHandler.logger20"));
}
use of java.io.BufferedOutputStream in project translationstudio8 by heartsome.
the class PreMachineTranslation method executeTranslation.
/**
* 根据构建参数执行预翻译 ;
* @throws InterruptedException
*/
public List<PreMachineTranslationCounter> executeTranslation(IProgressMonitor monitor) throws InterruptedException {
if (monitor == null) {
monitor = new NullProgressMonitor();
}
simpleMatchers = getMacthers();
if (null == simpleMatchers || simpleMatchers.isEmpty()) {
return this.transCounters;
}
monitor.beginTask("", this.xlfFiles.size());
monitor.setTaskName(Messages.getString("pretranslation.PreTranslation.task1"));
try {
for (String xlfPath : xlfFiles) {
if (monitor != null && monitor.isCanceled()) {
throw new InterruptedException();
}
currentCounter = new PreMachineTranslationCounter(xlfPath);
this.transCounters.add(currentCounter);
VTDNav vn = xlfHandler.getVnMap().get(xlfPath);
VTDUtils vu = new VTDUtils(vn);
AutoPilot ap = new AutoPilot(vu.getVTDNav());
int tuNumber = xlfHandler.getNodeCount(xlfPath, "/xliff/file//descendant::trans-unit[(source/text()!='' or source/*)]");
currentCounter.setTuNumber(tuNumber);
ap.selectXPath("/xliff/file");
String srcLang = "";
String tgtLang = "";
XMLModifier xm = new XMLModifier(vn);
IProgressMonitor monitor2 = new SubProgressMonitor(monitor, 1);
monitor2.beginTask(Messages.getString("pretranslation.PreTranslation.task2"), tuNumber);
while (ap.evalXPath() != -1) {
// 循环 file 节点
String _srcLang = vu.getCurrentElementAttribut("source-language", "");
String _tgtLang = vu.getCurrentElementAttribut("target-language", "");
if (!_srcLang.equals("")) {
srcLang = _srcLang;
}
if (!_tgtLang.equals("")) {
tgtLang = _tgtLang;
}
if (srcLang.equals("") || tgtLang.equals("")) {
continue;
}
keepCurrentMatchs(vu, _srcLang, _tgtLang, xm, monitor2);
}
monitor2.done();
FileOutputStream fos = new FileOutputStream(xlfPath);
BufferedOutputStream bos = new BufferedOutputStream(fos);
// 写入文件
xm.output(bos);
bos.close();
fos.close();
}
} catch (XPathParseException e) {
logger.error("", e);
e.printStackTrace();
} catch (NavException e) {
logger.error("", e);
e.printStackTrace();
} catch (ModifyException e) {
logger.error("", e);
e.printStackTrace();
} catch (XPathEvalException e) {
logger.error("", e);
e.printStackTrace();
} catch (UnsupportedEncodingException e) {
logger.error("", e);
e.printStackTrace();
} catch (FileNotFoundException e) {
logger.error("", e);
e.printStackTrace();
} catch (TranscodeException e) {
logger.error("", e);
e.printStackTrace();
} catch (IOException e) {
logger.error("", e);
e.printStackTrace();
}
monitor.done();
return this.transCounters;
}
use of java.io.BufferedOutputStream in project powermock by powermock.
the class DebuggingClassWriter method toByteArray.
public byte[] toByteArray() {
return (byte[]) java.security.AccessController.doPrivileged(new java.security.PrivilegedAction() {
public Object run() {
byte[] b = DebuggingClassWriter.super.toByteArray();
if (debugLocation != null) {
String dirs = className.replace('.', File.separatorChar);
try {
new File(debugLocation + File.separatorChar + dirs).getParentFile().mkdirs();
File file = new File(new File(debugLocation), dirs + ".class");
OutputStream out = new BufferedOutputStream(new FileOutputStream(file));
try {
out.write(b);
} finally {
out.close();
}
if (traceEnabled) {
file = new File(new File(debugLocation), dirs + ".asm");
out = new BufferedOutputStream(new FileOutputStream(file));
try {
ClassReader cr = new ClassReader(b);
PrintWriter pw = new PrintWriter(new OutputStreamWriter(out));
TraceClassVisitor tcv = new TraceClassVisitor(null, pw);
cr.accept(tcv, 0);
pw.flush();
} finally {
out.close();
}
}
} catch (IOException e) {
throw new CodeGenerationException(e);
}
}
return b;
}
});
}
use of java.io.BufferedOutputStream in project cassandra by apache.
the class OutputStreamBench method setUp.
@Setup
public void setUp(final Blackhole bh) {
StringBuilder sb = new StringBuilder();
for (int ii = 0; ii < 11; ii++) {
sb.append(BufferedDataOutputStreamTest.fourByte);
sb.append(BufferedDataOutputStreamTest.threeByte);
sb.append(BufferedDataOutputStreamTest.twoByte);
}
smallM = sb.toString();
sb = new StringBuilder();
while (sb.length() < 1024 * 12) {
sb.append(small);
}
large = sb.toString();
sb = new StringBuilder();
while (sb.length() < 1024 * 12) {
sb.append(smallM);
}
largeM = sb.toString();
hole = new BufferedOutputStream(new OutputStream() {
@Override
public void write(int b) throws IOException {
bh.consume(b);
}
@Override
public void write(byte[] b) throws IOException {
bh.consume(b);
}
@Override
public void write(byte[] b, int a, int c) throws IOException {
bh.consume(b);
bh.consume(a);
bh.consume(c);
}
});
streamA = new WrappedDataOutputStreamPlus(hole);
streamB = new BufferedDataOutputStreamPlus(new WritableByteChannel() {
@Override
public boolean isOpen() {
return true;
}
@Override
public void close() throws IOException {
}
@Override
public int write(ByteBuffer src) throws IOException {
bh.consume(src);
int remaining = src.remaining();
src.position(src.limit());
return remaining;
}
}, 8192);
}
Aggregations