Exemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: public void dump(java.nio.file.Path dbPath, java.nio.file.Path transactionalLogsPath, java.nio.file.Path archive, CompressionFormat format, System.Predicate<java.nio.file.Path> exclude) throws java.io.IOException
        public virtual void Dump(Path dbPath, Path transactionalLogsPath, Path archive, CompressionFormat format, System.Predicate <Path> exclude)
        {
            checkWritableDirectory(archive.Parent);
            _operations.Clear();

            VisitPath(dbPath, exclude);
            if (!Util.isSameOrChildPath(dbPath, transactionalLogsPath))
            {
                VisitPath(transactionalLogsPath, exclude);
            }

            _progressPrinter.reset();
            foreach (ArchiveOperation operation in _operations)
            {
                _progressPrinter.maxBytes += operation.Size;
                _progressPrinter.maxFiles += operation.IsFile ? 1 : 0;
            }

            using (ArchiveOutputStream stream = OpenArchiveOut(archive, format), Resource ignore = _progressPrinter.startPrinting())
            {
                foreach (ArchiveOperation operation in _operations)
                {
                    operation.AddToArchive(stream);
                }
            }
        }
Exemplo n.º 2
0
 /**
  * Copies the ArchiveEntry to the Output stream
  *
  * @param in
  *            the stream to read the data from
  * @param out
  *            the stream to write the data to
  * @param entry
  *            the entry to write
  * @throws IOException
  *             if data cannot be read or written
  */
 private void copyStream(java.io.InputStream inJ, ArchiveOutputStream outJ,
                         ArchiveEntry entry) //throws IOException
 {
     outJ.putArchiveEntry(entry);
     IOUtils.copy(inJ, outJ);
     outJ.closeArchiveEntry();
 }
Exemplo n.º 3
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private void writeFile(java.nio.file.Path file, org.apache.commons.compress.archivers.ArchiveOutputStream archiveStream) throws java.io.IOException
        private void WriteFile(Path file, ArchiveOutputStream archiveStream)
        {
            using (Stream @in = Files.newInputStream(file))
            {
                copy(@in, archiveStream, _progressPrinter);
            }
        }
Exemplo n.º 4
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: void addToArchive(org.apache.commons.compress.archivers.ArchiveOutputStream stream) throws java.io.IOException
            internal virtual void AddToArchive(ArchiveOutputStream stream)
            {
                ArchiveEntry entry = CreateEntry(File, Root, stream);

                stream.putArchiveEntry(entry);
                Operation.accept(stream);
                stream.closeArchiveEntry();
            }
Exemplo n.º 5
0
            public static ArchiveOutputStream Create(System.IO.Stream stream, ArchiveType type)
            {
                switch (type)
                {
                case ArchiveType.zip:
                    return(ArchiveOutputStream.CreateZipStream(stream));

                case ArchiveType.tgz:
                    return(ArchiveOutputStream.CreateTgzStream(stream));

                default:
                    throw new ArgumentException();
                }
            }
Exemplo n.º 6
0
        /// <summary>
        /// Archive a Directory.
        /// Assumes the Directory is fully populated with Files, Workspaces, and child Directories
        /// </summary>
        public async Task <ArchiveResult> ArchiveDirectory(Directory directory, ArchiveType type, bool includeIds)
        {
            var stream = new System.IO.MemoryStream();

            using (ArchiveOutputStream archiveStream = ArchiveOutputStream.Create(stream, type))
            {
                await ArchiveDirectory(directory, "", archiveStream, includeIds, includeDirName : false);
            }

            stream.Position = 0;

            return(new ArchiveResult
            {
                Data = stream,
                Name = $"{directory.GetExportName(includeIds)}.{type.GetExtension()}",
                Type = type.GetContentType()
            });
        }
Exemplo n.º 7
0
        private async Task ArchiveDirectory(Directory directory, string ancestors, ArchiveOutputStream archiveStream, bool includeIds, bool includeDirName)
        {
            var rootPath = $"{ancestors}{(includeDirName ? directory.GetExportName(includeIds) : string.Empty)}/";
            var fullPath = $"{ancestors}{directory.GetExportName(includeIds)}";

            foreach (var file in directory.Files.Where(f => f.WorkspaceId == null))
            {
                archiveStream.PutNextEntry($"{rootPath}{file.Name}", file.Content.Length);

                using (var sw = new System.IO.StreamWriter(archiveStream.Stream, leaveOpen: true))
                {
                    await sw.WriteAsync(file.Content);
                }

                archiveStream.CloseEntry();
            }

            foreach (var workspace in directory.Workspaces)
            {
                var path = $"{rootPath}__Workspaces__/{workspace.Name}/";

                archiveStream.PutNextEntry(path, 0);
                archiveStream.CloseEntry();

                foreach (var file in workspace.Files)
                {
                    archiveStream.PutNextEntry($"{path}{file.Name}", file.Content.Length);

                    using (var sw = new System.IO.StreamWriter(archiveStream.Stream, leaveOpen: true))
                    {
                        await sw.WriteAsync(file.Content);
                    }

                    archiveStream.CloseEntry();
                }
            }

            foreach (var dir in directory.Children)
            {
                await ArchiveDirectory(dir, $"{rootPath}", archiveStream, includeIds, true);
            }
        }
Exemplo n.º 8
0
        /// <summary>
        /// Archive a Project.
        /// Assumes all Directories are fully populated with Files, Workspaces, and child Directories
        /// </summary>
        public async Task <ArchiveResult> ArchiveProject(Project project, ArchiveType type, bool includeIds)
        {
            var stream = new System.IO.MemoryStream();

            using (ArchiveOutputStream archiveStream = ArchiveOutputStream.Create(stream, type))
            {
                foreach (var directory in project.Directories.Where(d => d.ParentId == null))
                {
                    await ArchiveDirectory(directory, "", archiveStream, includeIds, includeDirName : true);
                }
            }

            stream.Position = 0;

            return(new ArchiveResult
            {
                Data = stream,
                Name = $"{project.Name}.{type.GetExtension()}",
                Type = type.GetContentType()
            });
        }
Exemplo n.º 9
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#:
//ORIGINAL LINE: private org.apache.commons.compress.archivers.ArchiveEntry createEntry(java.nio.file.Path file, java.nio.file.Path root, org.apache.commons.compress.archivers.ArchiveOutputStream archive) throws java.io.IOException
            internal virtual ArchiveEntry CreateEntry(Path file, Path root, ArchiveOutputStream archive)
            {
                return(archive.createArchiveEntry(file.toFile(), "./" + root.relativize(file).ToString()));
            }
Exemplo n.º 10
0
        /**
         * Performs all changes collected in this ChangeSet on the input stream and
         * streams the result to the output stream. Perform may be called more than once.
         *
         * This method finishes the stream, no other entries should be added
         * after that.
         *
         * @param in
         *            the InputStream to perform the changes on
         * @param out
         *            the resulting OutputStream with all modifications
         * @throws IOException
         *             if an read/write error occurs
         * @return the results of this operation
         */
        public ChangeSetResults perform(ArchiveInputStream inJ, ArchiveOutputStream outJ)
        //throws IOException
        {
            ChangeSetResults results = new ChangeSetResults();

            java.util.Set <Change> workingSet = new java.util.LinkedHashSet <Change>(changes);

            for (java.util.Iterator <Change> it = workingSet.iterator(); it.hasNext();)
            {
                Change change = it.next();

                if (change.type() == Change.TYPE_ADD && change.isReplaceMode())
                {
                    copyStream(change.getInput(), outJ, change.getEntry());
                    it.remove();
                    results.addedFromChangeSet(change.getEntry().getName());
                }
            }

            ArchiveEntry entry = null;

            while ((entry = inJ.getNextEntry()) != null)
            {
                bool copy = true;

                for (java.util.Iterator <Change> it = workingSet.iterator(); it.hasNext();)
                {
                    Change change = it.next();

                    int    type = change.type();
                    String name = entry.getName();
                    if (type == Change.TYPE_DELETE && name != null)
                    {
                        if (name.equals(change.targetFile()))
                        {
                            copy = false;
                            it.remove();
                            results.deleted(name);
                            break;
                        }
                    }
                    else if (type == Change.TYPE_DELETE_DIR && name != null)
                    {
                        if (name.StartsWith(change.targetFile() + "/"))
                        {
                            copy = false;
                            results.deleted(name);
                            break;
                        }
                    }
                }

                if (copy)
                {
                    if (!isDeletedLater(workingSet, entry) && !results.hasBeenAdded(entry.getName()))
                    {
                        copyStream(inJ, outJ, entry);
                        results.addedFromStream(entry.getName());
                    }
                }
            }

            // Adds files which hasn't been added from the original and do not have replace mode on
            for (java.util.Iterator <Change> it = workingSet.iterator(); it.hasNext();)
            {
                Change change = it.next();

                if (change.type() == Change.TYPE_ADD &&
                    !change.isReplaceMode() &&
                    !results.hasBeenAdded(change.getEntry().getName()))
                {
                    copyStream(change.getInput(), outJ, change.getEntry());
                    it.remove();
                    results.addedFromChangeSet(change.getEntry().getName());
                }
            }
            outJ.finish();
            return(results);
        }