use of java.io.FileOutputStream in project liquibase by liquibase.
the class ConvertCommand method run.
@Override
protected CommandResult run() throws Exception {
List<ResourceAccessor> openers = new ArrayList<ResourceAccessor>();
openers.add(new FileSystemResourceAccessor());
openers.add(new ClassLoaderResourceAccessor());
if (classpath != null) {
openers.add(new FileSystemResourceAccessor(classpath));
}
ResourceAccessor resourceAccessor = new CompositeResourceAccessor(openers);
ChangeLogParser sourceParser = ChangeLogParserFactory.getInstance().getParser(src, resourceAccessor);
ChangeLogSerializer outSerializer = ChangeLogSerializerFactory.getInstance().getSerializer(out);
DatabaseChangeLog changeLog = sourceParser.parse(src, new ChangeLogParameters(), resourceAccessor);
File outFile = new File(out);
if (!outFile.exists()) {
outFile.getParentFile().mkdirs();
}
FileOutputStream outputStream = new FileOutputStream(outFile);
try {
outSerializer.write(changeLog.getChangeSets(), outputStream);
} finally {
outputStream.flush();
outputStream.close();
}
return new CommandResult("Converted successfully");
}
use of java.io.FileOutputStream in project android-gif-drawable by koral--.
the class ReLinker method unpackLibrary.
/**
* Attempts to unpack the given library to the workaround directory. Implements retry logic for
* IO operations to ensure they succeed.
*
* @param context {@link Context} to describe the location of the installed APK file
*/
private static File unpackLibrary(final Context context) {
final String outputFileName = MAPPED_BASE_LIB_NAME + BuildConfig.VERSION_NAME;
File outputFile = new File(context.getDir(LIB_DIR, Context.MODE_PRIVATE), outputFileName);
if (outputFile.isFile()) {
return outputFile;
}
final File cachedLibraryFile = new File(context.getCacheDir(), outputFileName);
if (cachedLibraryFile.isFile()) {
return cachedLibraryFile;
}
final String mappedSurfaceLibraryName = System.mapLibraryName(LibraryLoader.SURFACE_LIBRARY_NAME);
final FilenameFilter filter = new FilenameFilter() {
@Override
public boolean accept(File dir, String filename) {
return filename.startsWith(MAPPED_BASE_LIB_NAME) || filename.startsWith(mappedSurfaceLibraryName);
}
};
clearOldLibraryFiles(outputFile, filter);
clearOldLibraryFiles(cachedLibraryFile, filter);
final ApplicationInfo appInfo = context.getApplicationInfo();
final File apkFile = new File(appInfo.sourceDir);
ZipFile zipFile = null;
try {
zipFile = openZipFile(apkFile);
int tries = 0;
while (tries++ < MAX_TRIES) {
ZipEntry libraryEntry = findLibraryEntry(zipFile);
if (libraryEntry == null) {
throw new IllegalStateException("Library " + MAPPED_BASE_LIB_NAME + " for supported ABIs not found in APK file");
}
InputStream inputStream = null;
FileOutputStream fileOut = null;
try {
inputStream = zipFile.getInputStream(libraryEntry);
fileOut = new FileOutputStream(outputFile);
copy(inputStream, fileOut);
} catch (IOException e) {
if (tries > MAX_TRIES / 2) {
outputFile = cachedLibraryFile;
}
continue;
} finally {
closeSilently(inputStream);
closeSilently(fileOut);
}
setFilePermissions(outputFile);
break;
}
} finally {
//http://bugs.java.com/view_bug.do?bug_id=6389768
try {
if (zipFile != null) {
zipFile.close();
}
} catch (IOException ignored) {
}
}
return outputFile;
}
use of java.io.FileOutputStream in project AndroidAsync by koush.
the class AsyncHttpClient method executeFile.
public Future<File> executeFile(AsyncHttpRequest req, final String filename, final FileCallback callback) {
final File file = new File(filename);
file.getParentFile().mkdirs();
final OutputStream fout;
try {
fout = new BufferedOutputStream(new FileOutputStream(file), 8192);
} catch (FileNotFoundException e) {
SimpleFuture<File> ret = new SimpleFuture<File>();
ret.setComplete(e);
return ret;
}
final FutureAsyncHttpResponse cancel = new FutureAsyncHttpResponse();
final SimpleFuture<File> ret = new SimpleFuture<File>() {
@Override
public void cancelCleanup() {
try {
cancel.get().setDataCallback(new DataCallback.NullDataCallback());
cancel.get().close();
} catch (Exception e) {
}
try {
fout.close();
} catch (Exception e) {
}
file.delete();
}
};
ret.setParent(cancel);
execute(req, 0, cancel, new HttpConnectCallback() {
long mDownloaded = 0;
@Override
public void onConnectCompleted(Exception ex, final AsyncHttpResponse response) {
if (ex != null) {
try {
fout.close();
} catch (IOException e) {
}
file.delete();
invoke(callback, ret, response, ex, null);
return;
}
invokeConnect(callback, response);
final long contentLength = HttpUtil.contentLength(response.headers());
response.setDataCallback(new OutputStreamDataCallback(fout) {
@Override
public void onDataAvailable(DataEmitter emitter, ByteBufferList bb) {
mDownloaded += bb.remaining();
super.onDataAvailable(emitter, bb);
invokeProgress(callback, response, mDownloaded, contentLength);
}
});
response.setEndCallback(new CompletedCallback() {
@Override
public void onCompleted(Exception ex) {
try {
fout.close();
} catch (IOException e) {
ex = e;
}
if (ex != null) {
file.delete();
invoke(callback, ret, response, ex, null);
} else {
invoke(callback, ret, response, null, file);
}
}
});
}
});
return ret;
}
use of java.io.FileOutputStream in project android-gif-drawable by koral--.
the class GifSourcesResolver method getFileFromAssets.
private File getFileFromAssets(Context context, String filename) {
try {
File file = new File(context.getCacheDir(), filename);
final AssetFileDescriptor assetFileDescriptor = context.getResources().getAssets().openFd(filename);
FileInputStream input = assetFileDescriptor.createInputStream();
byte[] buf = new byte[(int) assetFileDescriptor.getDeclaredLength()];
int bytesRead = input.read(buf);
input.close();
if (bytesRead != buf.length) {
throw new IOException("Asset read failed");
}
FileOutputStream output = new FileOutputStream(file);
output.write(buf, 0, bytesRead);
output.close();
return file;
} catch (IOException ex) {
throw new IllegalStateException(ex);
}
}
use of java.io.FileOutputStream in project ion by koush.
the class StreamTests method testStream.
public void testStream() throws Exception {
new Random(39548394).nextBytes(random);
Ion.with(getContext()).load("http://localhost:" + port + "/").write(new FileOutputStream(getContext().getFileStreamPath("test")), true).get();
assertEquals(Md5.createInstance().update(random).digest(), Md5.digest(getContext().getFileStreamPath("test")));
}
Aggregations