private void addDirectoryToZipEntryList(
      File directory, String currentPath, ImmutableMap.Builder<File, ZipEntry> zipEntriesBuilder)
      throws IOException {
    Preconditions.checkNotNull(currentPath);

    for (File inputFile : directory.listFiles()) {
      String childPath = currentPath + (currentPath.isEmpty() ? "" : "/") + inputFile.getName();

      if (inputFile.isDirectory()) {
        addDirectoryToZipEntryList(inputFile, childPath, zipEntriesBuilder);
      } else {
        ZipEntry nextEntry = new ZipEntry(childPath);
        long fileLength = inputFile.length();
        if (fileLength > maxDeflatedBytes
            || EXTENSIONS_NOT_TO_DEFLATE.contains(Files.getFileExtension(inputFile.getName()))) {
          nextEntry.setMethod(ZipEntry.STORED);
          nextEntry.setCompressedSize(inputFile.length());
          nextEntry.setSize(inputFile.length());
          HashCode crc = ByteStreams.hash(Files.newInputStreamSupplier(inputFile), Hashing.crc32());
          nextEntry.setCrc(crc.padToLong());
        }

        zipEntriesBuilder.put(inputFile, nextEntry);
      }
    }
  }
  /** Extracts the archive resource and then runs the batch-import process on it. */
  protected void importDataArchive(
      final Resource resource,
      final ArchiveInputStream resourceStream,
      BatchImportOptions options) {

    final File tempDir = Files.createTempDir();
    try {
      ArchiveEntry archiveEntry;
      while ((archiveEntry = resourceStream.getNextEntry()) != null) {
        final File entryFile = new File(tempDir, archiveEntry.getName());
        if (archiveEntry.isDirectory()) {
          entryFile.mkdirs();
        } else {
          entryFile.getParentFile().mkdirs();

          Files.copy(
              new InputSupplier<InputStream>() {
                @Override
                public InputStream getInput() throws IOException {
                  return new CloseShieldInputStream(resourceStream);
                }
              },
              entryFile);
        }
      }

      importDataDirectory(tempDir, null, options);
    } catch (IOException e) {
      throw new RuntimeException(
          "Failed to extract data from '" + resource + "' to '" + tempDir + "' for batch import.",
          e);
    } finally {
      FileUtils.deleteQuietly(tempDir);
    }
  }
  @Before
  public void setup() throws IOException, InterruptedException {
    if (!WORK_DIR.isDirectory()) {
      Files.createParentDirs(new File(WORK_DIR, "dummy"));
    }

    // write out a few files
    for (int i = 0; i < 4; i++) {
      File fileName = new File(WORK_DIR, "file" + i);
      StringBuilder sb = new StringBuilder();

      // write as many lines as the index of the file
      for (int j = 0; j < i; j++) {
        sb.append("file" + i + "line" + j + "\n");
      }
      Files.write(sb.toString(), fileName, Charsets.UTF_8);
      ZipUtil.zipFile(new File(WORK_DIR, "file" + i + ".zip"), fileName);
      fileName.delete();
    }
    Thread.sleep(1500L); // make sure timestamp is later
    File emptyFile = new File(WORK_DIR, "emptylineFile");
    Files.write("\n", emptyFile, Charsets.UTF_8);
    ZipUtil.zipFile(new File(WORK_DIR, "emptylineFile.zip"), emptyFile);
    emptyFile.delete();
  }
  public static void compareNamespaces(
      @NotNull NamespaceDescriptor nsa,
      @NotNull NamespaceDescriptor nsb,
      boolean includeObject,
      @NotNull File txtFile) {
    String serialized = new NamespaceComparator(includeObject).doCompareNamespaces(nsa, nsb);
    try {
      for (; ; ) {
        String expected = Files.toString(txtFile, Charset.forName("utf-8")).replace("\r\n", "\n");

        if (expected.contains("kick me")) {
          // for developer
          System.err.println("generating " + txtFile);
          Files.write(serialized, txtFile, Charset.forName("utf-8"));
          continue;
        }

        // compare with hardcopy: make sure nothing is lost in output
        Assert.assertEquals(expected, serialized);
        break;
      }
    } catch (IOException e) {
      throw new RuntimeException(e);
    }
  }
示例#5
0
 private void addResourceProcessingSteps(
     Path sourcePath, Path destinationPath, ImmutableList.Builder<Step> stepsBuilder) {
   String sourcePathExtension =
       Files.getFileExtension(sourcePath.toString()).toLowerCase(Locale.US);
   switch (sourcePathExtension) {
     case "plist":
     case "stringsdict":
       LOG.debug("Converting plist %s to binary plist %s", sourcePath, destinationPath);
       stepsBuilder.add(
           new PlistProcessStep(
               sourcePath,
               destinationPath,
               ImmutableMap.<String, NSObject>of(),
               ImmutableMap.<String, NSObject>of(),
               PlistProcessStep.OutputFormat.BINARY));
       break;
     case "xib":
       String compiledNibFilename =
           Files.getNameWithoutExtension(destinationPath.toString()) + ".nib";
       Path compiledNibPath = destinationPath.getParent().resolve(compiledNibFilename);
       LOG.debug("Compiling XIB %s to NIB %s", sourcePath, destinationPath);
       stepsBuilder.add(
           new IbtoolStep(ibtool.getCommandPrefix(getResolver()), sourcePath, compiledNibPath));
       break;
     default:
       stepsBuilder.add(CopyStep.forFile(sourcePath, destinationPath));
       break;
   }
 }
 @Test
 public void createByteSourceFromFileTest() throws Exception {
   File f1 = new File("src/main/resources/sample.pdf");
   ByteSource byteSource = Files.asByteSource(f1);
   byte[] readBytes = byteSource.read();
   assertThat(readBytes, is(Files.toByteArray(f1)));
 }
 /** Walk project references recursively, adding thrift files to the provided list. */
 List<File> getRecursiveThriftFiles(MavenProject project, String outputDirectory, List<File> files)
     throws IOException {
   HashFunction hashFun = Hashing.md5();
   if (dependencyIncludes.contains(project.getArtifactId())) {
     File dir = new File(new File(project.getFile().getParent(), "target"), outputDirectory);
     if (dir.exists()) {
       URI baseDir = getFileURI(dir);
       for (File f : findThriftFilesInDirectory(dir)) {
         URI fileURI = getFileURI(f);
         String relPath = baseDir.relativize(fileURI).getPath();
         File destFolder = getResourcesOutputDirectory();
         destFolder.mkdirs();
         File destFile = new File(destFolder, relPath);
         if (!destFile.exists()
             || (destFile.isFile()
                 && !Files.hash(f, hashFun).equals(Files.hash(destFile, hashFun)))) {
           getLog()
               .info(
                   format("copying %s to %s", f.getCanonicalPath(), destFile.getCanonicalPath()));
           copyFile(f, destFile);
         }
         files.add(destFile);
       }
     }
   }
   Map<String, MavenProject> refs = project.getProjectReferences();
   for (String name : refs.keySet()) {
     getRecursiveThriftFiles(refs.get(name), outputDirectory, files);
   }
   return files;
 }
示例#8
0
 private String getFileContentsWithAbsolutePath(Path path) throws IOException {
   String platformExt = null;
   switch (Platform.detect()) {
     case LINUX:
       platformExt = "linux";
       break;
     case MACOS:
       platformExt = "macos";
       break;
     case WINDOWS:
       platformExt = "win";
       break;
     case FREEBSD:
       platformExt = "freebsd";
       break;
     case UNKNOWN:
       // Leave platformExt as null.
       break;
   }
   if (platformExt != null) {
     String extension = com.google.common.io.Files.getFileExtension(path.toString());
     String basename = com.google.common.io.Files.getNameWithoutExtension(path.toString());
     Path platformPath =
         extension.length() > 0
             ? path.getParent()
                 .resolve(String.format("%s.%s.%s", basename, platformExt, extension))
             : path.getParent().resolve(String.format("%s.%s", basename, platformExt));
     if (platformPath.toFile().exists()) {
       path = platformPath;
     }
   }
   return new String(Files.readAllBytes(path), UTF_8);
 }
  private void reportResults(JsTestResults results) {

    for (ReportType report : reports) {

      JsTestResultReporter reporter;

      // pick a reporter implementation
      if (report.getType().trim().equalsIgnoreCase("plain")) {
        reporter = new PlainReporter();
      } else {
        // default to plain reporter
        reporter = new PlainReporter();
      }

      if (report.getDestFile() == null) {
        error("Could not write a report, destFile attribute was not set");
        continue;
      }

      try {
        log("Writing report to " + report.getDestFile().getAbsolutePath());
        File outFile = report.getDestFile();
        Files.createParentDirs(outFile);
        Files.touch(outFile);
        Files.write(reporter.createReport(results), outFile, Charsets.UTF_8);
      } catch (IOException e) {
        error("Could not write report file: " + e.getMessage());
      }
    }
  }
 public boolean check() {
   final Properties oldProps = new Properties();
   if (BindingFileSearch.CACHE_LIST.exists()) {
     try {
       Reader propIn = Files.newReader(BindingFileSearch.CACHE_LIST, Charset.defaultCharset());
       oldProps.load(propIn);
     } catch (Exception ex) {
       LOG.debug(ex, ex);
     }
   }
   Map<String, String> oldBindings = Maps.fromProperties(oldProps);
   Map<String, String> newBindings = Maps.fromProperties(BindingFileSearch.CURRENT_PROPS);
   if (oldBindings.equals(newBindings)) {
     LOG.info("Found up-to-date binding class cache: skipping message binding.");
     return true;
   } else {
     MapDifference<String, String> diffBindings = Maps.difference(oldBindings, newBindings);
     LOG.info("Binding class cache expired (old,new): \n" + diffBindings.entriesDiffering());
     try {
       Files.deleteRecursively(SubDirectory.CLASSCACHE.getFile());
     } catch (IOException ex) {
       LOG.error(ex, ex);
     }
     SubDirectory.CLASSCACHE.getFile().mkdir();
     return false;
   }
 }
  @Test
  public void testDeleteRecursively() throws IOException {

    File tempDir = getTestTempDir();
    assertTrue(tempDir.exists());
    File subFile1 = new File(tempDir, "subFile1");
    Files.write(SOME_BYTES, subFile1);
    assertTrue(subFile1.exists());
    File subDir1 = new File(tempDir, "subDir1");
    subDir1.mkdirs();
    assertTrue(subDir1.exists());
    File subFile2 = new File(subDir1, "subFile2");
    Files.write(SOME_BYTES, subFile2);
    assertTrue(subFile2.exists());
    File subDir2 = new File(subDir1, "subDir2");
    subDir2.mkdirs();
    assertTrue(subDir2.exists());

    IOUtils.deleteRecursively(tempDir);

    assertFalse(tempDir.exists());
    assertFalse(subFile1.exists());
    assertFalse(subDir1.exists());
    assertFalse(subFile2.exists());
    assertFalse(subDir2.exists());
  }
  public static void main(String[] args) throws IOException {
    Closer closer = Closer.create();
    // copy a file
    File origin = new File("join_temp");
    File copy = new File("target_temp");

    try {
      BufferedReader reader = new BufferedReader(new FileReader("join_temp"));
      BufferedWriter writer = new BufferedWriter(new FileWriter("target_temp"));

      closer.register(reader);
      closer.register(writer);

      String line;

      while ((line = reader.readLine()) != null) {
        writer.write(line);
      }
    } catch (IOException e) {
      throw closer.rethrow(e);
    } finally {
      closer.close();
    }

    Files.copy(origin, copy);

    File moved = new File("moved");

    // moving renaming
    Files.move(copy, moved);

    // working files as string
    List<String> lines = Files.readLines(origin, Charsets.UTF_8);

    HashCode hashCode = Files.hash(origin, Hashing.md5());
    System.out.println(hashCode);

    // file write and append
    String hamlet = "To be, or not to be it is a question\n";
    File write_and_append = new File("write_and_append");

    Files.write(hamlet, write_and_append, Charsets.UTF_8);

    Files.append(hamlet, write_and_append, Charsets.UTF_8);

    //        write_and_append.deleteOnExit();

    Files.write("OverWrite the file", write_and_append, Charsets.UTF_8);

    // ByteSource ByteSink
    ByteSource fileBytes = Files.asByteSource(write_and_append);
    byte[] readBytes = fileBytes.read();
    // equals to pre line -> Files.toByteArray(write_and_append) == readBytes

    ByteSink fileByteSink = Files.asByteSink(write_and_append);
    fileByteSink.write(Files.toByteArray(write_and_append));

    BaseEncoding base64 = BaseEncoding.base64();
    System.out.println(base64.encode("123456".getBytes()));
  }
示例#13
0
  private static Map<String, Class<?>> defineClasses(
      List<ClassDefinition> classDefinitions, DynamicClassLoader classLoader) {
    ClassInfoLoader classInfoLoader =
        ClassInfoLoader.createClassInfoLoader(classDefinitions, classLoader);

    if (DUMP_BYTE_CODE_TREE) {
      ByteArrayOutputStream out = new ByteArrayOutputStream();
      DumpByteCodeVisitor dumpByteCode = new DumpByteCodeVisitor(new PrintStream(out));
      for (ClassDefinition classDefinition : classDefinitions) {
        dumpByteCode.visitClass(classDefinition);
      }
      System.out.println(new String(out.toByteArray(), StandardCharsets.UTF_8));
    }

    Map<String, byte[]> byteCodes = new LinkedHashMap<>();
    for (ClassDefinition classDefinition : classDefinitions) {
      ClassWriter cw = new SmartClassWriter(classInfoLoader);
      classDefinition.visit(cw);
      byte[] byteCode = cw.toByteArray();
      if (RUN_ASM_VERIFIER) {
        ClassReader reader = new ClassReader(byteCode);
        CheckClassAdapter.verify(reader, classLoader, true, new PrintWriter(System.out));
      }
      byteCodes.put(classDefinition.getType().getJavaClassName(), byteCode);
    }

    String dumpClassPath = DUMP_CLASS_FILES_TO.get();
    if (dumpClassPath != null) {
      for (Map.Entry<String, byte[]> entry : byteCodes.entrySet()) {
        File file =
            new File(
                dumpClassPath,
                ParameterizedType.typeFromJavaClassName(entry.getKey()).getClassName() + ".class");
        try {
          log.debug("ClassFile: " + file.getAbsolutePath());
          Files.createParentDirs(file);
          Files.write(entry.getValue(), file);
        } catch (IOException e) {
          log.error(e, "Failed to write generated class file to: %s" + file.getAbsolutePath());
        }
      }
    }
    if (DUMP_BYTE_CODE_RAW) {
      for (byte[] byteCode : byteCodes.values()) {
        ClassReader classReader = new ClassReader(byteCode);
        classReader.accept(
            new TraceClassVisitor(new PrintWriter(System.err)), ClassReader.SKIP_FRAMES);
      }
    }
    Map<String, Class<?>> classes = classLoader.defineClasses(byteCodes);
    try {
      for (Class<?> clazz : classes.values()) {
        Reflection.initialize(clazz);
      }
    } catch (VerifyError e) {
      throw new RuntimeException(e);
    }
    return classes;
  }
  private void checkThatTheFileWasReceivedSuccessfully(final File file) throws IOException {
    assertTrue("Should exist: " + file, file.exists());

    final ByteSource originalFile = Files.asByteSource(image.getFile());
    final ByteSource savedFile = Files.asByteSource(file);

    assertTrue(originalFile.contentEquals(savedFile));
  }
示例#15
0
 @Override
 public void writeJsonResultFileBody(final File file, final List<Defect> allDefectList)
     throws IOException {
   for (Defect defect : allDefectList) {
     Files.append(defect.toJson(), file, Charsets.UTF_8);
     Files.append(",\n", file, Charsets.UTF_8);
   }
 }
示例#16
0
  @Test
  public void testCallPloidyThree() throws Exception {
    Files.write(Resources.toByteArray(getClass().getResource("testfile2.bam")), bamFile);
    Files.write(Resources.toByteArray(getClass().getResource("hla-a.bed")), bedFile);

    new FilterConsensus(bamFile, bedFile, outputFile, gene, cdna, removeGaps, minimumBreadth, 3)
        .call();
    assertEquals(6, countLines(outputFile));
  }
 private File prepareInstallationDirectory() throws IOException {
   File tempDir = Files.createTempDir();
   assertTrue(new File(tempDir, "bin").mkdir());
   assertTrue(new File(tempDir, "conf").mkdir());
   Files.copy(
       new File(resourcesDirectory, "conf" + File.separator + "server.xml"),
       new File(tempDir, "conf" + File.separator + "server.xml"));
   return tempDir;
 }
 private File save(File src, File target) {
   try {
     Files.createParentDirs(target);
     Files.copy(src, target);
     return target;
   } catch (IOException e) {
     LOG.error(e.getMessage(), e);
     throw new RuntimeException(e);
   }
 }
 @Test
 public void copyToByteSinkTest() throws Exception {
   File dest = new File("src/test/resources/sampleCompany.pdf");
   dest.deleteOnExit();
   File source = new File("src/main/resources/sample.pdf");
   ByteSource byteSource = Files.asByteSource(source);
   ByteSink byteSink = Files.asByteSink(dest);
   byteSource.copyTo(byteSink);
   assertThat(Files.toByteArray(dest), is(Files.toByteArray(source)));
 }
示例#20
0
  @Test
  public void testPersistMergeCaseInsensitive() throws Exception {
    final long timestamp = System.currentTimeMillis();
    IncrementalIndex toPersist1 = IncrementalIndexTest.createCaseInsensitiveIndex(timestamp);

    IncrementalIndex toPersist2 =
        new IncrementalIndex(0L, QueryGranularity.NONE, new AggregatorFactory[] {});

    toPersist2.add(
        new MapBasedInputRow(
            timestamp,
            Arrays.asList("DIm1", "DIM2"),
            ImmutableMap.<String, Object>of(
                "dim1", "1", "dim2", "2", "DIm1", "10000", "DIM2", "100000000")));

    toPersist2.add(
        new MapBasedInputRow(
            timestamp,
            Arrays.asList("dIM1", "dIm2"),
            ImmutableMap.<String, Object>of("DIm1", "1", "DIM2", "2", "dim1", "5", "dim2", "6")));

    final File tempDir1 = Files.createTempDir();
    final File tempDir2 = Files.createTempDir();
    final File mergedDir = Files.createTempDir();
    try {
      QueryableIndex index1 = IndexIO.loadIndex(IndexMerger.persist(toPersist1, tempDir1));

      Assert.assertEquals(2, index1.getTimeColumn().getLength());
      Assert.assertEquals(
          Arrays.asList("dim1", "dim2"), Lists.newArrayList(index1.getAvailableDimensions()));
      Assert.assertEquals(2, index1.getColumnNames().size());

      QueryableIndex index2 = IndexIO.loadIndex(IndexMerger.persist(toPersist2, tempDir2));

      Assert.assertEquals(2, index2.getTimeColumn().getLength());
      Assert.assertEquals(
          Arrays.asList("dim1", "dim2"), Lists.newArrayList(index2.getAvailableDimensions()));
      Assert.assertEquals(2, index2.getColumnNames().size());

      QueryableIndex merged =
          IndexIO.loadIndex(
              IndexMerger.mergeQueryableIndex(
                  Arrays.asList(index1, index2), new AggregatorFactory[] {}, mergedDir));

      Assert.assertEquals(3, merged.getTimeColumn().getLength());
      Assert.assertEquals(
          Arrays.asList("dim1", "dim2"), Lists.newArrayList(merged.getAvailableDimensions()));
      Assert.assertEquals(2, merged.getColumnNames().size());
    } finally {
      FileUtils.deleteQuietly(tempDir1);
      FileUtils.deleteQuietly(tempDir2);
      FileUtils.deleteQuietly(mergedDir);
    }
  }
    public void process(File f) throws Exception {
      if (f.isDirectory()) {
        File[] files =
            f.listFiles(
                new FilenameFilter() {

                  @Override
                  public boolean accept(File dir, String name) {
                    return name.matches(FILE_PATTERN);
                  }
                });
        for (File ff : files) {
          byte[] bindingBytes = Files.toByteArray(ff);
          this.addCurrentBinding(bindingBytes, ff.getName(), "file:" + ff.getAbsolutePath());
        }
      } else {
        String digest = new BigInteger(Files.getDigest(f, Digest.MD5.get())).abs().toString(16);
        CURRENT_PROPS.put(BINDING_CACHE_JAR_PREFIX + f.getName(), digest);
        final JarFile jar = new JarFile(f);
        final List<JarEntry> jarList = Collections.list(jar.entries());
        for (final JarEntry j : jarList) {
          try {
            if (j.getName().matches(FILE_PATTERN)) {
              byte[] bindingBytes = ByteStreams.toByteArray(jar.getInputStream(j));
              String bindingName = j.getName();
              String bindingFullPath = "jar:file:" + f.getAbsolutePath() + "!/" + bindingName;
              this.addCurrentBinding(bindingBytes, bindingName, bindingFullPath);
            } else if (j.getName().matches(".*\\.class.{0,1}")) {
              final String classGuess =
                  j.getName().replaceAll("/", ".").replaceAll("\\.class.{0,1}", "");
              final Class candidate = ClassLoader.getSystemClassLoader().loadClass(classGuess);
              if (MSG_BASE_CLASS.isAssignableFrom(candidate)
                  || MSG_DATA_CLASS.isAssignableFrom(candidate)) {
                InputSupplier<InputStream> classSupplier =
                    Resources.newInputStreamSupplier(ClassLoader.getSystemResource(j.getName()));
                File destClassFile = SubDirectory.CLASSCACHE.getChildFile(j.getName());
                if (!destClassFile.exists()) {
                  Files.createParentDirs(destClassFile);
                  Files.copy(classSupplier, destClassFile);
                  Logs.extreme()
                      .debug("Caching: " + j.getName() + " => " + destClassFile.getAbsolutePath());
                }
                BINDING_CLASS_MAP.putIfAbsent(classGuess, candidate);
              }
            }
          } catch (RuntimeException ex) {
            LOG.error(ex, ex);
            jar.close();
            throw ex;
          }
        }
        jar.close();
      }
    }
 @Test
 public void testCopyStream() throws IOException {
   File tempDir = getTestTempDir();
   File subFile1 = new File(tempDir, "subFile1");
   Files.write(SOME_BYTES, subFile1);
   File subFile2 = new File(tempDir, "subFile2");
   IOUtils.copyURLToFile(subFile1.toURI().toURL(), subFile2);
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   Files.copy(subFile2, baos);
   assertArrayEquals(SOME_BYTES, baos.toByteArray());
 }
  private static void formatFile(@NonNull XmlFormatPreferences prefs, File file, boolean stdout) {
    if (file.isDirectory()) {
      File[] files = file.listFiles();
      if (files != null) {
        for (File child : files) {
          formatFile(prefs, child, stdout);
        }
      }
    } else if (file.isFile() && SdkUtils.endsWithIgnoreCase(file.getName(), DOT_XML)) {
      XmlFormatStyle style = null;
      if (file.getName().equals(SdkConstants.ANDROID_MANIFEST_XML)) {
        style = XmlFormatStyle.MANIFEST;
      } else {
        File parent = file.getParentFile();
        if (parent != null) {
          String parentName = parent.getName();
          ResourceFolderType folderType = ResourceFolderType.getFolderType(parentName);
          if (folderType == ResourceFolderType.LAYOUT) {
            style = XmlFormatStyle.LAYOUT;
          } else if (folderType == ResourceFolderType.VALUES) {
            style = XmlFormatStyle.RESOURCE;
          }
        }
      }

      try {
        String xml = Files.toString(file, Charsets.UTF_8);
        Document document = XmlUtils.parseDocumentSilently(xml, true);
        if (document == null) {
          System.err.println("Could not parse " + file);
          System.exit(1);
          return;
        }

        if (style == null) {
          style = XmlFormatStyle.get(document);
        }
        boolean endWithNewline = xml.endsWith("\n");
        int firstNewLine = xml.indexOf('\n');
        String lineSeparator =
            firstNewLine > 0 && xml.charAt(firstNewLine - 1) == '\r' ? "\r\n" : "\n";
        String formatted =
            XmlPrettyPrinter.prettyPrint(document, prefs, style, lineSeparator, endWithNewline);
        if (stdout) {
          System.out.println(formatted);
        } else {
          Files.write(formatted, file, Charsets.UTF_8);
        }
      } catch (IOException e) {
        System.err.println("Could not read " + file);
        System.exit(1);
      }
    }
  }
示例#24
0
 public static void main(String args[]) throws IOException {
   final String path = "C:\\GitHub\\mapfish-printV3\\core\\src\\test\\resources\\map-data";
   final File root = new File(path);
   final FluentIterable<File> files = Files.fileTreeTraverser().postOrderTraversal(root);
   for (File file : files) {
     if (Files.getFileExtension(file.getName()).equals("png")) {
       final BufferedImage img = ImageIO.read(file);
       writeUncompressedImage(img, file.getAbsolutePath());
     }
   }
 }
 private void assertFilesAreEqualIgnoringWhitespaces(File expected, File actual) throws Exception {
   String assertionMessage = "Expected content in " + expected + ", Actual content in " + actual;
   List<String> expectedLines = Files.readLines(expected, Charset.forName("UTF-8"));
   List<String> actualLines = Files.readLines(actual, Charset.forName("UTF-8"));
   assertEquals(assertionMessage, expectedLines.size(), actualLines.size());
   for (int i = 0, end = expectedLines.size(); i < end; i++) {
     String expectedLine = expectedLines.get(i);
     String actualLine = actualLines.get(i);
     assertEquals(assertionMessage, expectedLine.trim(), actualLine.trim());
   }
 }
示例#26
0
 /** required flags: model-dir input-file output-file */
 public static void main(String[] args) throws Exception {
   final FNModelOptions options = new FNModelOptions(args);
   final File inputFile = new File(options.inputFile.get());
   final File outputFile = new File(options.outputFile.get());
   final String modelDirectory = options.modelDirectory.get();
   final int numThreads = options.numThreads.present() ? options.numThreads.get() : 1;
   final Semafor semafor = getSemaforInstance(modelDirectory);
   semafor.runParser(
       Files.newReaderSupplier(inputFile, Charsets.UTF_8),
       Files.newWriterSupplier(outputFile, Charsets.UTF_8),
       numThreads);
 }
  @Override
  public void getSegmentFiles(DataSegment segment, File outDir) throws SegmentLoadingException {
    S3Coords s3Coords = new S3Coords(segment);

    log.info("Pulling index at path[%s] to outDir[%s]", s3Coords, outDir);

    if (!isObjectInBucket(s3Coords)) {
      throw new SegmentLoadingException("IndexFile[%s] does not exist.", s3Coords);
    }

    if (!outDir.exists()) {
      outDir.mkdirs();
    }

    if (!outDir.isDirectory()) {
      throw new ISE("outDir[%s] must be a directory.", outDir);
    }

    long startTime = System.currentTimeMillis();
    S3Object s3Obj = null;

    try {
      s3Obj = s3Client.getObject(new S3Bucket(s3Coords.bucket), s3Coords.path);

      InputStream in = null;
      try {
        in = s3Obj.getDataInputStream();
        final String key = s3Obj.getKey();
        if (key.endsWith(".zip")) {
          CompressionUtils.unzip(in, outDir);
        } else if (key.endsWith(".gz")) {
          final File outFile = new File(outDir, toFilename(key, ".gz"));
          ByteStreams.copy(new GZIPInputStream(in), Files.newOutputStreamSupplier(outFile));
        } else {
          ByteStreams.copy(
              in, Files.newOutputStreamSupplier(new File(outDir, toFilename(key, ""))));
        }
        log.info(
            "Pull of file[%s] completed in %,d millis",
            s3Obj, System.currentTimeMillis() - startTime);
      } catch (IOException e) {
        FileUtils.deleteDirectory(outDir);
        throw new SegmentLoadingException(e, "Problem decompressing object[%s]", s3Obj);
      } finally {
        Closeables.closeQuietly(in);
      }
    } catch (Exception e) {
      throw new SegmentLoadingException(e, e.getMessage());
    } finally {
      S3Utils.closeStreamsQuietly(s3Obj);
    }
  }
  @Before
  public void setUp() throws Exception {
    repositoryDirectory = new File("target/localrepository");
    repositoryDirectory.mkdirs();

    repository = new LocalRepositoryImpl(repositoryDirectory);

    File artifact =
        new File(repositoryDirectory, "com/bygg/bygg-test-artifact/1.2/bygg-test-artifact-1.2.jar");

    Files.createParentDirs(artifact);
    Files.append("lite data", artifact, Charset.forName("UTF-8"));
  }
示例#29
0
  @Test
  public void testCallKirExons() throws Exception {
    Files.write(
        Resources.toByteArray(getClass().getResource("2DL1_0020101.bwa.sorted.bam")), bamFile);
    Files.write(Resources.toByteArray(getClass().getResource("kir-2dl1.exons.bed")), bedFile);

    cdna = false;
    removeGaps = false;
    new FilterConsensus(
            bamFile, bedFile, outputFile, gene, cdna, removeGaps, minimumBreadth, expectedPloidy)
        .call();
    assertEquals(16, countLines(outputFile));
  }
示例#30
0
  @Before
  public void before() throws Exception {
    topSongsResultPath = tempFolder.newFile().toURI().toString();
    communitiesResultPath = tempFolder.newFile().toURI().toString();

    File tripletsFile = tempFolder.newFile();
    Files.write(MusicProfilesData.USER_SONG_TRIPLETS, tripletsFile, Charsets.UTF_8);
    tripletsPath = tripletsFile.toURI().toString();

    File mismatchesFile = tempFolder.newFile();
    Files.write(MusicProfilesData.MISMATCHES, mismatchesFile, Charsets.UTF_8);
    mismatchesPath = mismatchesFile.toURI().toString();
  }