use of java.io.FileInputStream in project buck by facebook.
the class ExopackageSoLoader method copySoFileIfRequired.
private static File copySoFileIfRequired(String libname) {
File libraryFile = new File(privateNativeLibsDir, libname + ".so");
if (libraryFile.exists()) {
return libraryFile;
}
if (!abi1Libraries.containsKey(libname) && !abi2Libraries.containsKey(libname)) {
return null;
}
String abiDir;
String sourceFilename;
if (abi1Libraries.containsKey(libname)) {
sourceFilename = abi1Libraries.get(libname);
abiDir = Build.CPU_ABI;
} else {
sourceFilename = abi2Libraries.get(libname);
abiDir = Build.CPU_ABI2;
}
String sourcePath = nativeLibsDir + abiDir + "/" + sourceFilename;
try {
InputStream in = null;
OutputStream out = null;
try {
in = new BufferedInputStream(new FileInputStream(sourcePath));
out = new BufferedOutputStream(new FileOutputStream(libraryFile));
byte[] buffer = new byte[4 * 1024];
int len;
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
} finally {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return libraryFile;
}
use of java.io.FileInputStream in project druid by druid-io.
the class S3DataSegmentPullerTest method testGZUncompress.
@Test
public void testGZUncompress() throws ServiceException, IOException, SegmentLoadingException {
final String bucket = "bucket";
final String keyPrefix = "prefix/dir/0";
final RestS3Service s3Client = EasyMock.createStrictMock(RestS3Service.class);
final byte[] value = bucket.getBytes("utf8");
final File tmpFile = temporaryFolder.newFile("gzTest.gz");
try (OutputStream outputStream = new GZIPOutputStream(new FileOutputStream(tmpFile))) {
outputStream.write(value);
}
final S3Object object0 = new S3Object();
object0.setBucketName(bucket);
object0.setKey(keyPrefix + "/renames-0.gz");
object0.setLastModifiedDate(new Date(0));
object0.setDataInputStream(new FileInputStream(tmpFile));
final File tmpDir = temporaryFolder.newFolder("gzTestDir");
EasyMock.expect(s3Client.getObjectDetails(EasyMock.eq(object0.getBucketName()), EasyMock.eq(object0.getKey()))).andReturn(null).once();
EasyMock.expect(s3Client.getObjectDetails(EasyMock.eq(object0.getBucketName()), EasyMock.eq(object0.getKey()))).andReturn(object0).once();
EasyMock.expect(s3Client.getObject(EasyMock.eq(object0.getBucketName()), EasyMock.eq(object0.getKey()))).andReturn(object0).once();
S3DataSegmentPuller puller = new S3DataSegmentPuller(s3Client);
EasyMock.replay(s3Client);
FileUtils.FileCopyResult result = puller.getSegmentFiles(new S3DataSegmentPuller.S3Coords(bucket, object0.getKey()), tmpDir);
EasyMock.verify(s3Client);
Assert.assertEquals(value.length, result.size());
File expected = new File(tmpDir, "renames-0");
Assert.assertTrue(expected.exists());
Assert.assertEquals(value.length, expected.length());
}
use of java.io.FileInputStream in project android by cSploit.
the class NetworkHelper method getIfaceGateway.
public static String getIfaceGateway(String iface) {
Pattern pattern = Pattern.compile(String.format("^%s\\t+00000000\\t+([0-9A-F]{8})", iface), Pattern.CASE_INSENSITIVE);
BufferedReader reader = null;
String line;
try {
reader = new BufferedReader(new InputStreamReader(new FileInputStream("/proc/net/route")));
while ((line = reader.readLine()) != null) {
Matcher matcher = pattern.matcher(line);
if (!matcher.find()) {
continue;
}
String rawAddress = matcher.group(1);
StringBuilder sb = new StringBuilder();
for (int i = 6; ; i -= 2) {
String part = rawAddress.substring(i, i + 2);
sb.append(Integer.parseInt(part, 16));
if (i > 0) {
sb.append('.');
} else {
break;
}
}
String res = sb.toString();
Logger.debug("found system default gateway for interface " + iface + ": " + res);
return res;
}
} catch (IOException e) {
System.errorLogging(e);
} finally {
IOUtils.closeQuietly(reader);
}
Logger.warning("falling back to ip");
return getIfaceGatewayUsingIp(iface);
}
use of java.io.FileInputStream in project lucida by claritylab.
the class FileUtils method readString.
/**
* Reads a string from a file, using the given encoding.
*
* @param input input file
* @param encoding file encoding
* @return string
*/
public static String readString(File input, String encoding) throws IOException {
StringBuffer buffer = new StringBuffer();
FileInputStream fis = new FileInputStream(input);
BufferedReader reader = new BufferedReader(new InputStreamReader(fis, encoding));
for (String nextLine; (nextLine = reader.readLine()) != null; ) buffer.append(nextLine + "\n");
reader.close();
return buffer.toString();
}
use of java.io.FileInputStream in project buck by facebook.
the class AaptPackageResourcesIntegrationTest method testAaptPackageIsScrubbed.
@Test
public void testAaptPackageIsScrubbed() throws IOException {
AssumeAndroidPlatform.assumeSdkIsAvailable();
workspace.runBuckBuild(MAIN_BUILD_TARGET).assertSuccess();
Path aaptOutput = workspace.getPath(BuildTargets.getGenPath(filesystem, BuildTargetFactory.newInstance(MAIN_BUILD_TARGET).withFlavors(AndroidBinaryGraphEnhancer.AAPT_PACKAGE_FLAVOR), AaptPackageResources.RESOURCE_APK_PATH_FORMAT));
Date dosEpoch = new Date(ZipUtil.dosToJavaTime(ZipConstants.DOS_FAKE_TIME));
try (ZipInputStream is = new ZipInputStream(new FileInputStream(aaptOutput.toFile()))) {
for (ZipEntry entry = is.getNextEntry(); entry != null; entry = is.getNextEntry()) {
assertThat(entry.getName(), new Date(entry.getTime()), Matchers.equalTo(dosEpoch));
}
}
}
Aggregations