Search in sources :

Example 21 with Files

use of java.nio.file.Files in project hmftools by hartwigmedical.

the class FilteredSVWriter method processVcfFiles.

public void processVcfFiles() {
    final List<File> vcfFiles;
    final Path root = Paths.get(mVcfFileLocation);
    try (final Stream<Path> stream = Files.walk(root, 5, FileVisitOption.FOLLOW_LINKS)) {
        vcfFiles = stream.map(p -> p.toFile()).filter(p -> !p.isDirectory()).filter(p_ -> p_.getName().endsWith("somaticSV_bpi.vcf")).collect(Collectors.toList());
        LOGGER.debug("found {} BPI VCF files", vcfFiles.size());
        // add the filtered and passed SV entries for each file
        for (final File vcfFile : vcfFiles) {
            if (vcfFile.isDirectory())
                continue;
            if (!vcfFile.getPath().contains("structuralVariants/bpi/"))
                continue;
            if (!vcfFile.getName().endsWith("somaticSV_bpi.vcf"))
                continue;
            LOGGER.debug("BPI VCF path({}) file({})", vcfFile.getPath(), vcfFile.getName());
            // extract sampleId from the directory or file name
            String[] itemsStr = vcfFile.getName().split("_");
            if (itemsStr.length != 4)
                continue;
            String sampleId = itemsStr[1];
            LOGGER.debug("sampleId({})", sampleId);
            List<StructuralVariant> variants = readFromVcf(vcfFile.getPath());
            generateFilteredSVFile(variants, sampleId);
        }
        if (mFileWriter != null)
            mFileWriter.close();
    } catch (Exception e) {
    }
}
Also used : Path(java.nio.file.Path) LineIterator(htsjdk.tribble.readers.LineIterator) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) StandardOpenOption(java.nio.file.StandardOpenOption) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) StructuralVariant(com.hartwig.hmftools.common.variant.structural.StructuralVariant) File(java.io.File) List(java.util.List) AbstractFeatureReader(htsjdk.tribble.AbstractFeatureReader) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) FileVisitOption(java.nio.file.FileVisitOption) Paths(java.nio.file.Paths) StructuralVariantFactory(com.hartwig.hmftools.common.variant.structural.StructuralVariantFactory) VariantContext(htsjdk.variant.variantcontext.VariantContext) VCFCodec(htsjdk.variant.vcf.VCFCodec) Path(java.nio.file.Path) LogManager(org.apache.logging.log4j.LogManager) File(java.io.File) StructuralVariant(com.hartwig.hmftools.common.variant.structural.StructuralVariant) IOException(java.io.IOException)

Example 22 with Files

use of java.nio.file.Files in project hmftools by hartwigmedical.

the class SvVCFAnnotator method processVcfFiles.

public void processVcfFiles() {
    final List<File> vcfFiles;
    final Path root = Paths.get(mVcfFileLocation);
    try (final Stream<Path> stream = Files.walk(root, 5, FileVisitOption.FOLLOW_LINKS)) {
        vcfFiles = stream.map(p -> p.toFile()).filter(p -> !p.isDirectory()).filter(p_ -> p_.getName().endsWith("somaticSV_bpi.vcf")).collect(Collectors.toList());
        LOGGER.debug("found {} BPI VCF files", vcfFiles.size());
        // add the filtered and passed SV entries for each file
        for (final File vcfFile : vcfFiles) {
            if (vcfFile.isDirectory())
                continue;
            if (!vcfFile.getPath().contains("structuralVariants/bpi/"))
                continue;
            if (!vcfFile.getName().endsWith("somaticSV_bpi.vcf"))
                continue;
            LOGGER.debug("BPI VCF path({}) file({})", vcfFile.getPath(), vcfFile.getName());
            // extract sampleId from the directory or file name
            String[] itemsStr = vcfFile.getName().split("_");
            if (itemsStr.length != 4)
                continue;
            String sampleId = itemsStr[1];
            LOGGER.debug("sampleId({})", sampleId);
            List<VariantContext> variants = readFromVcf(vcfFile.getPath());
            for (final VariantContext variant : variants) {
                if (variant.hasAttribute("IMPRECISE")) {
                    LOGGER.debug("var({}) has imprecise call", variant.getID());
                }
            }
        // generateFilteredSVFile(variants, sampleId);
        }
        if (mFileWriter != null)
            mFileWriter.close();
    } catch (Exception e) {
    }
}
Also used : Path(java.nio.file.Path) LineIterator(htsjdk.tribble.readers.LineIterator) Files(java.nio.file.Files) BufferedWriter(java.io.BufferedWriter) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) StructuralVariant(com.hartwig.hmftools.common.variant.structural.StructuralVariant) File(java.io.File) List(java.util.List) AbstractFeatureReader(htsjdk.tribble.AbstractFeatureReader) Stream(java.util.stream.Stream) Lists(com.google.common.collect.Lists) Logger(org.apache.logging.log4j.Logger) FileVisitOption(java.nio.file.FileVisitOption) Paths(java.nio.file.Paths) StructuralVariantFactory(com.hartwig.hmftools.common.variant.structural.StructuralVariantFactory) VariantContext(htsjdk.variant.variantcontext.VariantContext) VCFCodec(htsjdk.variant.vcf.VCFCodec) Path(java.nio.file.Path) LogManager(org.apache.logging.log4j.LogManager) VariantContext(htsjdk.variant.variantcontext.VariantContext) File(java.io.File) IOException(java.io.IOException)

Example 23 with Files

use of java.nio.file.Files in project support-core-plugin by jenkinsci.

the class OtherConfigFilesComponentTest method missingFile.

@Test
public void missingFile() throws Exception {
    File file = new File(j.jenkins.root, "x.xml");
    FileUtils.writeStringToFile(file, xml);
    Map<String, Content> contents = new HashMap<>();
    new OtherConfigFilesComponent().addContents(new Container() {

        @Override
        public void add(Content content) {
            contents.put(MessageFormat.format(content.getName(), (Object[]) content.getFilterableParameters()), content);
        }
    });
    Files.delete(file.toPath());
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    Content content = contents.get("jenkins-root-configuration-files/x.xml");
    assertNotNull(content);
    content.writeTo(baos);
    assertThat("routine build should not issue warnings", logging.getRecords().stream().filter(// TODO .record(…, WARNING) does not accomplish this
    lr -> lr.getLevel().intValue() >= Level.WARNING.intValue()).map(lr -> lr.getSourceClassName() + "." + lr.getSourceMethodName() + ": " + lr.getMessage()).collect(// LogRecord does not override toString
    Collectors.toList()), emptyIterable());
    assertThat(baos.toString(), allOf(containsString("FileNotFoundException"), containsString(file.getAbsolutePath())));
}
Also used : ByteArrayOutputStream(java.io.ByteArrayOutputStream) Files(java.nio.file.Files) Matchers(org.hamcrest.Matchers) HashMap(java.util.HashMap) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) Collectors(java.util.stream.Collectors) File(java.io.File) MessageFormat(java.text.MessageFormat) Level(java.util.logging.Level) Rule(org.junit.Rule) LoggerRule(org.jvnet.hudson.test.LoggerRule) Map(java.util.Map) Container(com.cloudbees.jenkins.support.api.Container) Content(com.cloudbees.jenkins.support.api.Content) SecretBytes(com.cloudbees.plugins.credentials.SecretBytes) Secret(hudson.util.Secret) JenkinsRule(org.jvnet.hudson.test.JenkinsRule) Assert(org.junit.Assert) Before(org.junit.Before) Container(com.cloudbees.jenkins.support.api.Container) HashMap(java.util.HashMap) Content(com.cloudbees.jenkins.support.api.Content) ByteArrayOutputStream(java.io.ByteArrayOutputStream) File(java.io.File) Test(org.junit.Test)

Example 24 with Files

use of java.nio.file.Files in project keycloak by keycloak.

the class CopyDependencies method main.

public static void main(String[] args) throws IOException {
    String version = args[2];
    Path repository = new File(args[0]).toPath().resolve("org").resolve("keycloak");
    Path targetRoot = new File(args[1]).toPath().resolve(version);
    BufferedReader br = new BufferedReader(new InputStreamReader(CopyDependencies.class.getResourceAsStream("files")));
    Path target = targetRoot;
    for (String l = br.readLine(); l != null; l = br.readLine()) {
        if (l.startsWith("./")) {
            target = targetRoot.resolve(l.replace("./", "").replace('/', File.separatorChar));
            if (!target.toFile().isDirectory()) {
                target.toFile().mkdirs();
            }
        } else if (l.trim().length() > 0) {
            String[] t = l.trim().split(":");
            String artifactName = t[0];
            String destName = t.length == 1 ? artifactName : t[1];
            File artifactDir = repository.resolve(artifactName).resolve(version).toFile();
            for (File f : artifactDir.listFiles((file, name) -> name.contains(".tar.gz") || name.contains(".zip"))) {
                Files.copy(f.toPath(), target.resolve(f.getName().replace(artifactName, destName)), StandardCopyOption.REPLACE_EXISTING);
            }
            System.out.println(artifactName);
        }
    }
    br.close();
}
Also used : Path(java.nio.file.Path) Files(java.nio.file.Files) IOException(java.io.IOException) BufferedReader(java.io.BufferedReader) InputStreamReader(java.io.InputStreamReader) Path(java.nio.file.Path) File(java.io.File) StandardCopyOption(java.nio.file.StandardCopyOption) InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) File(java.io.File)

Example 25 with Files

use of java.nio.file.Files in project keycloak by keycloak.

the class TomcatDeploymentArchiveProcessorUtils method copyWarClasspathFilesToCommonTomcatClasspath.

/**
 * Tomcat doesn't load files (e. g. secure-portal keystore) from webarchive classpath
 * we need to copy it to common classpath /catalina_home/lib
 * @param archive
 */
public static void copyWarClasspathFilesToCommonTomcatClasspath(Archive<?> archive) {
    Stream<Node> contentOfArchiveClasspath = archive.getContent(archivePath -> archivePath.get().startsWith(WAR_CLASSPATH)).values().stream().filter(node -> StringUtils.countMatches(node.toString(), "/") == // get only files not directories
    StringUtils.countMatches(WAR_CLASSPATH, "/") && node.toString().contains("."));
    String catalinaHome = System.getProperty("app.server.home");
    contentOfArchiveClasspath.forEach((Node node) -> {
        Path p = Paths.get(node.toString());
        File outputFile = new File(catalinaHome + "/lib/" + p.getFileName().toString());
        if (!outputFile.exists()) {
            try {
                Files.copy(node.getAsset().openStream(), outputFile.toPath());
            } catch (IOException e) {
                throw new RuntimeException("Couldn't copy classpath files from deployed war to common classpath of tomcat", e);
            }
        }
    });
}
Also used : DeploymentArchiveProcessorUtils(org.keycloak.testsuite.utils.arquillian.DeploymentArchiveProcessorUtils) WebArchive(org.jboss.shrinkwrap.api.spec.WebArchive) ClassAsset(org.jboss.shrinkwrap.api.asset.ClassAsset) Files(java.nio.file.Files) Logger(org.jboss.logging.Logger) ApplicationPath(javax.ws.rs.ApplicationPath) Set(java.util.Set) IOException(java.io.IOException) Archive(org.jboss.shrinkwrap.api.Archive) Node(org.jboss.shrinkwrap.api.Node) IOUtil.loadXML(org.keycloak.testsuite.utils.io.IOUtil.loadXML) StringUtils(org.apache.commons.lang3.StringUtils) Collectors(java.util.stream.Collectors) StringAsset(org.jboss.shrinkwrap.api.asset.StringAsset) File(java.io.File) IOUtils(org.apache.commons.io.IOUtils) IOUtil.removeElementFromDoc(org.keycloak.testsuite.utils.io.IOUtil.removeElementFromDoc) Stream(java.util.stream.Stream) Paths(java.nio.file.Paths) Document(org.w3c.dom.Document) Path(java.nio.file.Path) IOUtil.documentToString(org.keycloak.testsuite.utils.io.IOUtil.documentToString) IOUtil.modifyDocElementValue(org.keycloak.testsuite.utils.io.IOUtil.modifyDocElementValue) ApplicationPath(javax.ws.rs.ApplicationPath) Path(java.nio.file.Path) Node(org.jboss.shrinkwrap.api.Node) IOUtil.documentToString(org.keycloak.testsuite.utils.io.IOUtil.documentToString) IOException(java.io.IOException) File(java.io.File)

Aggregations

Files (java.nio.file.Files)247 IOException (java.io.IOException)213 Path (java.nio.file.Path)199 List (java.util.List)177 Collectors (java.util.stream.Collectors)157 Paths (java.nio.file.Paths)135 File (java.io.File)130 ArrayList (java.util.ArrayList)117 Map (java.util.Map)111 Set (java.util.Set)97 Collections (java.util.Collections)89 Arrays (java.util.Arrays)81 Stream (java.util.stream.Stream)78 HashMap (java.util.HashMap)75 HashSet (java.util.HashSet)58 InputStream (java.io.InputStream)56 Collection (java.util.Collection)55 Logger (org.slf4j.Logger)54 Pattern (java.util.regex.Pattern)53 Optional (java.util.Optional)51