try (TarOutputStream tOut = new TarOutputStream( compression.compress(new BufferedOutputStream( Files.newOutputStream(tarFile.toPath()))), encoding)) { tOut.setDebug(true); if (longFileMode.isTruncateMode()) { tOut.setLongFileMode(TarOutputStream.LONGFILE_TRUNCATE); } else if (longFileMode.isFailMode() || longFileMode.isOmitMode()) { tOut.setLongFileMode(TarOutputStream.LONGFILE_ERROR); } else if (longFileMode.isPosixMode()) { tOut.setLongFileMode(TarOutputStream.LONGFILE_POSIX); } else { tOut.setLongFileMode(TarOutputStream.LONGFILE_GNU);
String entryName, Map<String, String> headers) throws IOException { String name = "./PaxHeaders.X/" + stripTo7Bits(entryName); if (name.length() >= TarConstants.NAMELEN) { name = name.substring(0, TarConstants.NAMELEN - 1); transferModTime(entry, pex); putNextEntry(pex); write(data); closeEntry();
/** * Ends the TAR archive and closes the underlying OutputStream. * This means that finish() is called followed by calling the * TarBuffer's close(). * @throws IOException on error */ @Override public void close() throws IOException { if (!finished) { finish(); } if (!closed) { buffer.close(); out.close(); closed = true; } }
TarOutputStream tos = new TarOutputStream(gzos); entry.setSize(srcFile.length()); tos.putNextEntry(entry); int read = fis.read(buffer); if (read <= 0) { break; } tos.write(buffer, 0, read); tos.closeEntry(); tos.close();
TarOutputStream tos = new TarOutputStream(os); try { TarEntry te = new TarEntry("/bar/foo"); byte[] data = "some-content".getBytes("UTF-8"); te.setSize(data.length); tos.putNextEntry(te); tos.write(data); tos.closeEntry(); tos.flush(); tos.finish(); } finally { tos.close();
public void storeRecord(String path, InputStream data, long size) throws IOException { path = path.replaceAll("/+", "/").replace("\\", "/"); if(exportedFiles.contains(path)) { log.debug(String.format("Skipping already stored entry '%s'", path)); return; } TarEntry ze = new TarEntry(path); ze.setSize(size); outputStream.putNextEntry(ze); copyStream(data, outputStream, true, false); outputStream.closeEntry(); exportedFiles.add(path); }
tar_out = new TarOutputStream(gzip_out); tar_out.putNextEntry(entry); if (!entry.isDirectory()) { FileUtil.copyStream(tar_in, tar_out, buf); tar_out.closeEntry(); tar_out.flush(); completedOK = true;
tOut.putNextEntry(te); int count = 0; do { tOut.write(buffer, 0, count); count = in.read(buffer, 0, buffer.length); } while (count != -1); tOut.closeEntry(); } finally { FileUtils.close(in);
@Override protected void doExecute(final OutputStream outStr) throws Exception { TarOutputStream tarOutStr; try { tarOutStr = new TarOutputStream(outStr); } catch (Exception e) { throw new GradleException(String.format("Could not create TAR '%s'.", tarFile), e); } tarOutStr.setLongFileMode(TarOutputStream.LONGFILE_GNU); stream.process(new StreamAction(tarOutStr)); tarOutStr.close(); } });
public TarOutput(OutputStream os) { outputStream = new TarOutputStream(new BufferedOutputStream(os)); }
/** * Writes bytes to the current tar archive entry. * * This method simply calls write(byte[], int, int). * * @param wBuf The buffer to write to the archive. * @throws IOException on error */ @Override public void write(byte[] wBuf) throws IOException { write(wBuf, 0, wBuf.length); }
public void close() { try { outputStream.close(); exportedFiles = null; } catch (IOException ioe) { log.error("Unexpected exception while closing zip stream", ioe); } }
TarOutputStream tos = new TarOutputStream(gzos); entry.setSize(srcFile.length()); tos.putNextEntry(entry); int read = fis.read(buffer); if (read <= 0) { break; } tos.write(buffer, 0, read); tos.closeEntry(); tos.close();
TarOutputStream tos = new TarOutputStream(os); try { TarEntry te = new TarEntry("/bar/foo"); byte[] data = "some-content".getBytes("UTF-8"); te.setSize(data.length); tos.putNextEntry(te); tos.write(data); tos.closeEntry(); tos.flush(); tos.finish(); } finally { tos.close();
private void addFile (TarEntry entry, TarOutputStream tar_out, InputStream in, long size, byte[] buf) throws IOException { entry.setModTime(System.currentTimeMillis()); entry.setSize(size); tar_out.putNextEntry(entry); FileUtil.copyStream(in, tar_out, buf); tar_out.closeEntry(); } }
/** * Writes a byte to the current tar archive entry. * * This method simply calls read(byte[], int, int). * * @param b The byte written. * @throws IOException on error */ @Override public void write(int b) throws IOException { oneBuf[0] = (byte) b; write(oneBuf, 0, 1); }
public void cancel() { try { outputStream.close(); file.delete(); exportedFiles = null; } catch (IOException ioe) { log.error("Unexpected exception while closing zip stream", ioe); } }
protected int putFileContent(Launcher launcher, String containerId, String path, String filename, byte[] content, Integer mode) throws IOException, InterruptedException { TarEntry entry = new TarEntry(filename); entry.setUserId(0); entry.setGroupId(0); entry.setSize(content.length); if (mode != null) { entry.setMode(mode); } ByteArrayOutputStream out = new ByteArrayOutputStream(); TarOutputStream tar = new TarOutputStream(out); tar.putNextEntry(entry); tar.write(content); tar.closeEntry(); tar.close(); ArgumentListBuilder args = new ArgumentListBuilder() .add("cp", "-", containerId + ":" + path); return launchDockerCLI(launcher, args) .stdin(new ByteArrayInputStream(out.toByteArray())) .stderr(launcher.getListener().getLogger()).join(); }
transferModTime(entry, longLinkEntry); putNextEntry(longLinkEntry); write(encodedName.array(), encodedName.arrayOffset(), len); write(0); // NUL terminator closeEntry(); } else if (longFileMode != LONGFILE_TRUNCATE) { throw new RuntimeException(fieldName + " '" + name //NOSONAR
private void visitDir(FileCopyDetails dirDetails) { try { // Trailing slash on name indicates entry is a directory TarEntry archiveEntry = new TarEntry(dirDetails.getRelativePath().getPathString() + '/'); archiveEntry.setModTime(getArchiveTimeFor(dirDetails)); archiveEntry.setMode(UnixStat.DIR_FLAG | dirDetails.getMode()); tarOutStr.putNextEntry(archiveEntry); tarOutStr.closeEntry(); } catch (Exception e) { throw new GradleException(String.format("Could not add %s to TAR '%s'.", dirDetails, tarFile), e); } } }