use of java.io.BufferedOutputStream in project jersey by jersey.
the class JarUtils method createJarFile.
public static File createJarFile(final String name, final Suffix s, final String base, final Map<String, String> entries) throws IOException {
final File tempJar = File.createTempFile(name, "." + s);
tempJar.deleteOnExit();
final JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(tempJar)), new Manifest());
final Set<String> usedSegments = new HashSet<String>();
for (final Map.Entry<String, String> entry : entries.entrySet()) {
for (final String path : getPaths(entry.getValue())) {
if (usedSegments.contains(path)) {
continue;
}
usedSegments.add(path);
final JarEntry e = new JarEntry(path);
jos.putNextEntry(e);
jos.closeEntry();
}
final JarEntry e = new JarEntry(entry.getValue());
jos.putNextEntry(e);
final InputStream f = new BufferedInputStream(new FileInputStream(base + entry.getKey()));
final byte[] buf = new byte[1024];
int read = 1024;
while ((read = f.read(buf, 0, read)) != -1) {
jos.write(buf, 0, read);
}
jos.closeEntry();
}
jos.close();
return tempJar;
}
use of java.io.BufferedOutputStream in project k-9 by k9mail.
the class ImapConnection method setUpStreamsAndParser.
private void setUpStreamsAndParser(InputStream input, OutputStream output) {
inputStream = new PeekableInputStream(new BufferedInputStream(input, BUFFER_SIZE));
responseParser = new ImapResponseParser(inputStream);
outputStream = new BufferedOutputStream(output, BUFFER_SIZE);
}
use of java.io.BufferedOutputStream in project jna by java-native-access.
the class TlbImp method writeTextFile.
private void writeTextFile(String filename, String str) throws IOException {
String file = this.comRootDir + File.separator + filename;
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(file));
bos.write(str.getBytes());
bos.close();
}
use of java.io.BufferedOutputStream in project hadoop by apache.
the class TestContainerLogsPage method testContainerLogPageAccess.
@Test(timeout = 10000)
public void testContainerLogPageAccess() throws IOException {
// SecureIOUtils require Native IO to be enabled. This test will run
// only if it is enabled.
assumeTrue(NativeIO.isAvailable());
String user = "randomUser" + System.currentTimeMillis();
File absLogDir = null, appDir = null, containerDir = null, syslog = null;
try {
// target log directory
absLogDir = new File("target", TestContainerLogsPage.class.getSimpleName() + "LogDir").getAbsoluteFile();
absLogDir.mkdir();
Configuration conf = new Configuration();
conf.set(YarnConfiguration.NM_LOG_DIRS, absLogDir.toURI().toString());
conf.set(CommonConfigurationKeysPublic.HADOOP_SECURITY_AUTHENTICATION, "kerberos");
UserGroupInformation.setConfiguration(conf);
NodeHealthCheckerService healthChecker = createNodeHealthCheckerService(conf);
healthChecker.init(conf);
LocalDirsHandlerService dirsHandler = healthChecker.getDiskHandler();
// Add an application and the corresponding containers
RecordFactory recordFactory = RecordFactoryProvider.getRecordFactory(conf);
long clusterTimeStamp = 1234;
ApplicationId appId = BuilderUtils.newApplicationId(recordFactory, clusterTimeStamp, 1);
Application app = mock(Application.class);
when(app.getAppId()).thenReturn(appId);
// Making sure that application returns a random user. This is required
// for SecureIOUtils' file owner check.
when(app.getUser()).thenReturn(user);
ApplicationAttemptId appAttemptId = BuilderUtils.newApplicationAttemptId(appId, 1);
ContainerId container1 = BuilderUtils.newContainerId(recordFactory, appId, appAttemptId, 0);
// Testing secure read access for log files
// Creating application and container directory and syslog file.
appDir = new File(absLogDir, appId.toString());
appDir.mkdir();
containerDir = new File(appDir, container1.toString());
containerDir.mkdir();
syslog = new File(containerDir, "syslog");
syslog.createNewFile();
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(syslog));
out.write("Log file Content".getBytes());
out.close();
Context context = mock(Context.class);
ConcurrentMap<ApplicationId, Application> appMap = new ConcurrentHashMap<ApplicationId, Application>();
appMap.put(appId, app);
when(context.getApplications()).thenReturn(appMap);
ConcurrentHashMap<ContainerId, Container> containers = new ConcurrentHashMap<ContainerId, Container>();
when(context.getContainers()).thenReturn(containers);
when(context.getLocalDirsHandler()).thenReturn(dirsHandler);
MockContainer container = new MockContainer(appAttemptId, new AsyncDispatcher(), conf, user, appId, 1);
container.setState(ContainerState.RUNNING);
context.getContainers().put(container1, container);
ContainersLogsBlock cLogsBlock = new ContainersLogsBlock(context);
Map<String, String> params = new HashMap<String, String>();
params.put(YarnWebParams.CONTAINER_ID, container1.toString());
params.put(YarnWebParams.CONTAINER_LOG_TYPE, "syslog");
Injector injector = WebAppTests.testPage(ContainerLogsPage.class, ContainersLogsBlock.class, cLogsBlock, params, (Module[]) null);
PrintWriter spyPw = WebAppTests.getPrintWriter(injector);
verify(spyPw).write("Exception reading log file. Application submitted by '" + user + "' doesn't own requested log file : syslog");
} finally {
if (syslog != null) {
syslog.delete();
}
if (containerDir != null) {
containerDir.delete();
}
if (appDir != null) {
appDir.delete();
}
if (absLogDir != null) {
absLogDir.delete();
}
}
}
use of java.io.BufferedOutputStream in project hadoop by apache.
the class SwiftNativeOutputStream method partUpload.
/**
* Upload a single partition. This deletes the local backing-file,
* and re-opens it to create a new one.
* @param closingUpload is this the final upload of an upload
* @throws IOException on IO problems
*/
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
private void partUpload(boolean closingUpload) throws IOException {
if (backupStream != null) {
backupStream.close();
}
if (closingUpload && partUpload && backupFile.length() == 0) {
//skipping the upload if
// - it is close time
// - the final partition is 0 bytes long
// - one part has already been written
SwiftUtils.debug(LOG, "skipping upload of 0 byte final partition");
delete(backupFile);
} else {
partUpload = true;
boolean uploadSuccess = false;
int attempt = 0;
while (!uploadSuccess) {
try {
++attempt;
bytesUploaded += uploadFilePartAttempt(attempt);
uploadSuccess = true;
} catch (IOException e) {
LOG.info("Upload failed " + e, e);
if (attempt > ATTEMPT_LIMIT) {
throw e;
}
}
}
delete(backupFile);
partNumber++;
blockOffset = 0;
if (!closingUpload) {
//if not the final upload, create a new output stream
backupFile = newBackupFile();
backupStream = new BufferedOutputStream(new FileOutputStream(backupFile));
}
}
}
Aggregations