Java 类com.google.common.io.Files 实例源码

项目:bromium    文件:DslStepsDumperTest.java   
@Test
public void dumpsStepsReplacingAliases() throws IOException {
    Map<String, String> firstStep = new HashMap<>();
    firstStep.put(EVENT, loadPageActionName);
    firstStep.put(aliasUrl, aliasUrlValue);

    Map<String, String> secondStep = new HashMap<>();
    secondStep.put(EVENT, typeInNameInputActionName);
    secondStep.put(aliasText, aliasTextValue);

    TestScenarioSteps testScenarioSteps = new TestScenarioSteps();
    testScenarioSteps.add(firstStep);
    testScenarioSteps.add(secondStep);


    Map<String, ApplicationActionConfiguration> actionConfigurationMap = createAliasesMockConfiguration();

    StepsDumper stepsDumper = new DslStepsDumper(actionConfigurationMap);
    stepsDumper.dump(testScenarioSteps, outputFilename);

    List<String> lines = Files.readLines(outputFile, Charsets.UTF_8);
    assertEquals(2, lines.size());
    assertEquals("loadPage: Load text-field.html page ", lines.get(0));
    assertEquals("typeInNameInput: Type admin in name input ", lines.get(1));
}
项目:ProjectAres    文件:MapDefinition.java   
public boolean shouldReload() {
    if(context == null) return true;
    if(!configuration.autoReload()) return false;
    if(context.loadedFiles().isEmpty()) return configuration.reloadWhenError();

    try {
        for(Map.Entry<Path, HashCode> loaded : context.loadedFiles().entrySet()) {
            HashCode latest = Files.hash(loaded.getKey().toFile(), Hashing.sha256());
            if(!latest.equals(loaded.getValue())) return true;
        }

        return false;
    } catch (IOException e) {
        return true;
    }
}
项目:state-channels    文件:FileBlockReader.java   
@Override
public Iterator<ChannelTransaction> readAll() throws IOException {
    close();
    ByteBuffer buffer = Files.map(file);
    return new Iterator<ChannelTransaction>() {
        @Override
        public boolean hasNext() {
            return buffer.position() < buffer.limit();
        }

        @Override
        public ChannelTransaction next() {
            int l = buffer.getInt();
            byte[] signature = new byte[CryptoUtil.SIGNATURE_LENGTH];
            buffer.get(signature);
            byte[] data = new byte[l - CryptoUtil.SIGNATURE_LENGTH];
            buffer.get(data);
            return new ChannelTransaction(blockId.getChannel(), blockId.getBlockNumber(), data, signature);
        }
    };
}
项目:drift    文件:PemReader.java   
private static PKCS8EncodedKeySpec readPrivateKey(File keyFile, Optional<String> keyPassword)
        throws IOException, GeneralSecurityException
{
    String content = Files.toString(keyFile, US_ASCII);

    Matcher matcher = KEY_PATTERN.matcher(content);
    if (!matcher.find()) {
        throw new KeyStoreException("found no private key: " + keyFile);
    }
    byte[] encodedKey = base64Decode(matcher.group(1));

    if (!keyPassword.isPresent()) {
        return new PKCS8EncodedKeySpec(encodedKey);
    }

    EncryptedPrivateKeyInfo encryptedPrivateKeyInfo = new EncryptedPrivateKeyInfo(encodedKey);
    SecretKeyFactory keyFactory = SecretKeyFactory.getInstance(encryptedPrivateKeyInfo.getAlgName());
    SecretKey secretKey = keyFactory.generateSecret(new PBEKeySpec(keyPassword.get().toCharArray()));

    Cipher cipher = Cipher.getInstance(encryptedPrivateKeyInfo.getAlgName());
    cipher.init(DECRYPT_MODE, secretKey, encryptedPrivateKeyInfo.getAlgParameters());

    return encryptedPrivateKeyInfo.getKeySpec(cipher);
}
项目:tac-kbp-eal    文件:ScoreKBPAgainstERE.java   
public void finish() throws IOException {
  outputDir.mkdirs();

  final ImmutableSetMultimap<String, String> mentionAlignmentFailures =
      mentionAlignmentFailuresB.build();
  log.info("Of {} system responses, got {} mention alignment failures",
      numResponses.size(), mentionAlignmentFailures.size());

  final File serializedFailuresFile = new File(outputDir, "alignmentFailures.json");
  final JacksonSerializer serializer =
      JacksonSerializer.builder().forJson().prettyOutput().build();
  serializer.serializeTo(mentionAlignmentFailures, Files.asByteSink(serializedFailuresFile));

  final File failuresCount = new File(outputDir, "alignmentFailures.count.txt");
  serializer.serializeTo(mentionAlignmentFailures.size(), Files.asByteSink(failuresCount));
}
项目:cmakeify    文件:TestCmakeify.java   
@Test
public void complicatedSelfHost() throws IOException {
  File yaml = new File("test-files/complicatedSelfHost/cmakeify.yml");
  yaml.getParentFile().mkdirs();
  Files.write("includes: [extra-includes]\n" +
          "android:\n" +
          "  flavors:\n" +
          "    myflags:\n" +
          "      - -DANDROID\n" +
          "  lib: libbob.a\n" +
          "  ndk:\n" +
          "    platforms: [21, 22]\n",
      yaml, StandardCharsets.UTF_8);
  String result1 = main("-wf", yaml.getParent(), "--dump");
  yaml.delete();
  Files.write(result1, yaml, StandardCharsets.UTF_8);
  System.out.print(result1);
  String result2 = main("-wf", yaml.getParent(), "--dump");
  assertThat(result2).isEqualTo(result1);
  assertThat(result2).contains("-DANDROID");
  assertThat(result2).doesNotContain("default-flavor");
}
项目:Reer    文件:SimpleTemplateOperation.java   
@Override
public void generate() {
    try {
        target.getParentFile().mkdirs();
        SimpleTemplateEngine templateEngine = new SimpleTemplateEngine();
        String templateText = Resources.asCharSource(templateURL, CharsetToolkit.getDefaultSystemCharset()).read();
        Template template = templateEngine.createTemplate(templateText);
        Writer writer = Files.asCharSink(target, Charsets.UTF_8).openStream();
        try {
            template.make(bindings).writeTo(writer);
        } finally {
            writer.close();
        }
    } catch (Exception ex) {
        throw new GradleException("Could not generate file " + target + ".", ex);
    }
}
项目:SkyDocs    文件:ProjectsFrame.java   
/**
 * Saves the projects history.
 */

public final void saveHistory() {
    try {
        final StringBuilder builder = new StringBuilder();
        for(int i = 0; i < projectsModel.size(); i++) {
            builder.append(projectsModel.getElementAt(i) + System.lineSeparator());
        }
        Files.write(builder.toString(), new File(Utils.getParentFolder(), Constants.FILE_GUI_HISTORY), StandardCharsets.UTF_8);
    }
    catch(final Exception ex) {
        ex.printStackTrace(guiPrintStream);
        ex.printStackTrace();
        JOptionPane.showMessageDialog(ProjectsFrame.this, String.format(Constants.GUI_DIALOG_ERROR_MESSAGE, ex.getMessage()), ex.getClass().getName(), JOptionPane.ERROR_MESSAGE);
    }
}
项目:QDrill    文件:TestSimpleLimit.java   
private void verifyLimitCount(DrillbitContext bitContext, UserServer.UserClientConnection connection, String testPlan, int expectedCount) throws Throwable {
  final PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
  final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/limit/" + testPlan), Charsets.UTF_8));
  final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
  final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
  final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));
  int recordCount = 0;
  while(exec.next()) {
    recordCount += exec.getRecordCount();
  }

  assertEquals(expectedCount, recordCount);

  if(context.getFailureCause() != null) {
    throw context.getFailureCause();
  }

  assertTrue(!context.isFailed());
}
项目:flume-release-1.7.0    文件:TestTaildirSource.java   
@Test
public void testLifecycle() throws IOException, InterruptedException {
  File f1 = new File(tmpDir, "file1");
  Files.write("file1line1\nfile1line2\n", f1, Charsets.UTF_8);

  Context context = new Context();
  context.put(POSITION_FILE, posFilePath);
  context.put(FILE_GROUPS, "f1");
  context.put(FILE_GROUPS_PREFIX + "f1", tmpDir.getAbsolutePath() + "/file1$");
  Configurables.configure(source, context);

  for (int i = 0; i < 3; i++) {
    source.start();
    source.process();
    assertTrue("Reached start or error", LifecycleController.waitForOneOf(
        source, LifecycleState.START_OR_ERROR));
    assertEquals("Server is started", LifecycleState.START,
        source.getLifecycleState());

    source.stop();
    assertTrue("Reached stop or error",
        LifecycleController.waitForOneOf(source, LifecycleState.STOP_OR_ERROR));
    assertEquals("Server is stopped", LifecycleState.STOP,
        source.getLifecycleState());
  }
}
项目:dble    文件:DbleServer.java   
private void initZkDnindex() {
    //upload the dnindex data to zk
    try {
        if (dnIndexLock.acquire(30, TimeUnit.SECONDS)) {
            try {
                File file = new File(SystemConfig.getHomePath(), "conf" + File.separator + "dnindex.properties");
                String path = KVPathUtil.getDnIndexNode();
                CuratorFramework zk = ZKUtils.getConnection();
                if (zk.checkExists().forPath(path) == null) {
                    zk.create().creatingParentsIfNeeded().forPath(path, Files.toByteArray(file));
                }
            } finally {
                dnIndexLock.release();
            }
        }
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
项目:cdep    文件:TestCDep.java   
@Test
public void sqlite() throws Exception {
  CDepYml config = new CDepYml();
  System.out.printf(new Yaml().dump(config));
  File yaml = new File(".test-files/firebase/cdep.yml");
  yaml.getParentFile().mkdirs();
  Files.write("builders: [cmake, cmakeExamples]\n"
          + "dependencies:\n"
          + "- compile: com.github.jomof:sqlite:3.16.2-rev45\n",
      yaml, StandardCharsets.UTF_8);
  String result1 = main("show", "manifest", "-wf", yaml.getParent());
  yaml.delete();
  Files.write(result1, yaml, StandardCharsets.UTF_8);
  System.out.print(result1);
  String result = main("-wf", yaml.getParent());
  System.out.printf(result);
}
项目:flow-platform    文件:CredentialController.java   
private void handleAndroidFile(CredentialDetail detail, MultipartFile file) throws IOException {
    if (!(detail instanceof AndroidCredentialDetail)) {
        return;
    }

    if (file == null || file.isEmpty()) {
        return;
    }

    AndroidCredentialDetail androidDetail = (AndroidCredentialDetail) detail;
    String extension = Files.getFileExtension(file.getOriginalFilename());

    if (!ANDROID_EXTENSIONS.contains(extension)) {
        throw new IllegalParameterException("Illegal android cert file");
    }

    String destFileName = getFileName(file.getOriginalFilename());
    Path destPath = credentailFilePath(destFileName);

    file.transferTo(destPath.toFile());
    androidDetail.setFile(new FileResource(file.getOriginalFilename(), destPath.toString()));
}
项目:CustomWorldGen    文件:UserList.java   
public void writeChanges() throws IOException
{
    Collection<V> collection = this.values.values();
    String s = this.gson.toJson((Object)collection);
    BufferedWriter bufferedwriter = null;

    try
    {
        bufferedwriter = Files.newWriter(this.saveFile, Charsets.UTF_8);
        bufferedwriter.write(s);
    }
    finally
    {
        IOUtils.closeQuietly((Writer)bufferedwriter);
    }
}
项目:train-simulator    文件:StatisticsController.java   
@Deprecated
public void save() {
  String stats = collect();
  String filename = AppConfig.outputDir + "/" + map.getSimpleFileName() + ".csv";

  // if file exists, remove it
  (new File(filename)).delete();

  CharSink sink = Files.asCharSink(new File(filename), Charsets.UTF_8);
  try {
    sink.write(stats);
  } catch (IOException e) {
    e.printStackTrace();
  }

  logger.info("Exported statistics to: {}", filename);
}
项目:tac-kbp-eal    文件:TestLDCIO.java   
public void testArgumentRoundtrip(AssessmentSpecFormats.Format format) throws IOException {
  final File tmpDir = Files.createTempDir();
  tmpDir.deleteOnExit();

  final ArgumentStore store1 = AssessmentSpecFormats.createSystemOutputStore(tmpDir, format);
  store1.write(
      ArgumentOutput.from(docid, ImmutableList.of(arg), ImmutableMap.of(arg.item(), argMetadata)));
  store1.close();

  final ArgumentStore source2 = AssessmentSpecFormats.openSystemOutputStore(tmpDir, format);
  final ArgumentOutput rereadArg = source2.read(docid);
  source2.close();

  assertEquals(1, rereadArg.size());
  assertEquals(arg, Iterables.getFirst(rereadArg.scoredResponses(), null));
  assertEquals(argMetadata, rereadArg.metadata(arg.item()));
}
项目:drift    文件:ReloadableSslContext.java   
public boolean updateState()
        throws IOException
{
    // only check contents if length or modified time changed
    long newLastModified = file.lastModified();
    long newLength = file.length();
    if (lastModified == newLastModified && length == newLength) {
        return false;
    }

    // update stats
    lastModified = newLastModified;
    length = newLength;

    // check if contents changed
    HashCode newHashCode = Files.hash(file, sha256());
    if (Objects.equals(hashCode, newHashCode)) {
        return false;
    }
    hashCode = newHashCode;
    return true;
}
项目:flume-release-1.7.0    文件:TestLogFile.java   
@Test
public void testOperationRecordUpdater() throws Exception {
  File tempDir = Files.createTempDir();
  File temp = new File(tempDir, "temp");
  final RandomAccessFile tempFile = new RandomAccessFile(temp, "rw");
  for (int i = 0; i < 5000; i++) {
    tempFile.write(LogFile.OP_RECORD);
  }
  tempFile.seek(0);
  LogFile.OperationRecordUpdater recordUpdater = new LogFile
      .OperationRecordUpdater(temp);
  //Convert every 10th byte into a noop byte
  for (int i = 0; i < 5000; i += 10) {
    recordUpdater.markRecordAsNoop(i);
  }
  recordUpdater.close();

  tempFile.seek(0);
  // Verify every 10th byte is actually a NOOP
  for (int i = 0; i < 5000; i += 10) {
    tempFile.seek(i);
    Assert.assertEquals(LogFile.OP_NOOP, tempFile.readByte());
  }
}
项目:AptSpring    文件:ConfigurationTests.java   
@Test
public void testCycleInImports() throws IOException {
  File outputDir = Files.createTempDir();
  System.out.println("Generating into " + outputDir.getAbsolutePath());

  assertAbout(javaSources())
          .that(Arrays.asList(definitionClass, definitionClass2CausesDefinitionCycle))
          .processedWith(new VerifiedSpringConfiguration())
          .failsToCompile()
          .withErrorContaining("Cycle in @Configuration class @Imports test.TestClass1 -> test.TestClass2")
          .in(definitionClass)
          .onLine(12)
          .and()
          .withErrorContaining("Cycle in @Configuration class @Imports test.TestClass2 -> test.TestClass1")
          .in(definitionClass2CausesDefinitionCycle)
          .onLine(12);   
}
项目:QDrill    文件:TestOptiqPlans.java   
private SimpleRootExec doPhysicalTest(final DrillbitContext bitContext, UserClientConnection connection, String file)
    throws Exception {
  new NonStrictExpectations() {
    {
      bitContext.getMetrics();
      result = new MetricRegistry();
      bitContext.getAllocator();
      result = RootAllocatorFactory.newRoot(config);
      bitContext.getConfig();
      result = config;
    }
  };

  final StoragePluginRegistry reg = new StoragePluginRegistry(bitContext);

  final PhysicalPlanReader reader = new PhysicalPlanReader(config, config.getMapper(),
      CoordinationProtos.DrillbitEndpoint.getDefaultInstance(), reg);
  final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile(file), Charsets.UTF_8));
  final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(config);
  final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
  final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false)
      .iterator().next()));
  return exec;
}
项目:QDrill    文件:TestUnionExchange.java   
@Test
public void twoBitTwoExchangeTwoEntryRun() throws Exception {
  RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();

  try (Drillbit bit1 = new Drillbit(CONFIG, serviceSet);
      Drillbit bit2 = new Drillbit(CONFIG, serviceSet);
      DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator());) {

    bit1.run();
    bit2.run();
    client.connect();
    List<QueryDataBatch> results = client.runQuery(org.apache.drill.exec.proto.UserBitShared.QueryType.PHYSICAL,
        Files.toString(FileUtils.getResourceAsFile("/sender/union_exchange.json"),
            Charsets.UTF_8));
    int count = 0;
    for (QueryDataBatch b : results) {
      if (b.getHeader().getRowCount() != 0) {
        count += b.getHeader().getRowCount();
      }
      b.release();
    }
    assertEquals(150, count);
  }
}
项目:test.rockitizer    文件:FileAssertion.java   
@Override
public void proceed() {
    File recordFolder = new File( recordPath );
    File replayFolder = new File( replayPath );

    for (File recordFile : Files.fileTreeTraverser().preOrderTraversal(recordFolder)) {

        String relativePath = recordFolder.toURI().relativize(recordFile.toURI()).getPath();
        File replayFile = new File(replayFolder + "/" + relativePath );

        LOGGER.debug("asserting: source " + recordFile.getAbsolutePath() + " with target "  + replayFile.getAbsolutePath() );

        try { 
            assertTrue(" matching file "  + replayFile.getAbsolutePath() + " must exist", replayFile.exists()==true);
        } catch (AssertionError e) {
            throw new AssertionException(" matching file "  + replayFile.getAbsolutePath() + " must exist "  , e);
        }


    }       
}
项目:QDrill    文件:TestBroadcastExchange.java   
@Test
public void TestMultipleSendLocationBroadcastExchange() throws Exception {
  RemoteServiceSet serviceSet = RemoteServiceSet.getLocalServiceSet();

  try (Drillbit bit1 = new Drillbit(CONFIG, serviceSet);
      Drillbit bit2 = new Drillbit(CONFIG, serviceSet);
      DrillClient client = new DrillClient(CONFIG, serviceSet.getCoordinator())) {

    bit1.run();
    bit2.run();
    client.connect();

    String physicalPlan = Files.toString(
        FileUtils.getResourceAsFile("/sender/broadcast_exchange_long_run.json"), Charsets.UTF_8);
    List<QueryDataBatch> results = client.runQuery(QueryType.PHYSICAL, physicalPlan);
    int count = 0;
    for (QueryDataBatch b : results) {
      if (b.getHeader().getRowCount() != 0) {
        count += b.getHeader().getRowCount();
      }
      b.release();
    }
    System.out.println(count);
  }
}
项目:anki-cards-web-browser    文件:Exporter.java   
private void moveAndRenameImageFiles() throws AnkiExpectedExportingException {
    HashMap<String, String> imageNamesDictionary = parser.getImageNamesDictionary();

    File imagesFolder = new File(destinationFolder, "anki-images");
    //noinspection ResultOfMethodCallIgnored
    imagesFolder.mkdirs();

    imageNamesDictionary.forEach((currentName, targetName) -> {
        File originalFile    = new File(parser.getUnzippedToFolder(), currentName);
        File destinationFile = new File(imagesFolder, targetName);

        try {
            Files.copy(originalFile, destinationFile);
        } catch (IOException e) {
            throw new AnkiExpectedExportingException("Cannot move "+originalFile+" to "+destinationFile);
        }
    });
}
项目:CoreX    文件:ResourcePackManager.java   
public ResourcePackManager(File path) {
    if (!path.exists()) {
        path.mkdirs();
    } else if (!path.isDirectory()) {
        throw new IllegalArgumentException(Server.getInstance().getLanguage()
                .translateString("nukkit.resources.invalid-path", path.getName()));
    }

    List<ResourcePack> loadedResourcePacks = new ArrayList<>();
    for (File pack : path.listFiles()) {
        try {
            ResourcePack resourcePack = null;

            if (!pack.isDirectory()) { //directory resource packs temporarily unsupported
                switch (Files.getFileExtension(pack.getName())) {
                    case "zip":
                    case "mcpack":
                        resourcePack = new ZippedResourcePack(pack);
                        break;
                    default:
                        Server.getInstance().getLogger().warning(Server.getInstance().getLanguage()
                                .translateString("nukkit.resources.unknown-format", pack.getName()));
                        break;
                }
            }

            if (resourcePack != null) {
                loadedResourcePacks.add(resourcePack);
                this.resourcePacksById.put(resourcePack.getPackId(), resourcePack);
            }
        } catch (IllegalArgumentException e) {
            Server.getInstance().getLogger().warning(Server.getInstance().getLanguage()
                    .translateString("nukkit.resources.fail", pack.getName(), e.getMessage()));
        }
    }

    this.resourcePacks = loadedResourcePacks.toArray(new ResourcePack[loadedResourcePacks.size()]);
    Server.getInstance().getLogger().info(Server.getInstance().getLanguage()
            .translateString("nukkit.resources.success", String.valueOf(this.resourcePacks.length)));
}
项目:QDrill    文件:TestSimpleUnion.java   
@Test
public void testUnion(@Injectable final DrillbitContext bitContext, @Injectable UserServer.UserClientConnection connection) throws Throwable {
  new NonStrictExpectations() {{
    bitContext.getMetrics(); result = new MetricRegistry();
    bitContext.getAllocator(); result = RootAllocatorFactory.newRoot(c);
    bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c);
    bitContext.getConfig(); result = c;
    bitContext.getCompiler(); result = CodeCompiler.getTestCompiler(c);
  }};

  final PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
  final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/union/test1.json"), Charsets.UTF_8));
  final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
  final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
  final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));

  final int[] counts = new int[]{100,50};
  int i = 0;
  while(exec.next()) {
    System.out.println("iteration count:" + exec.getRecordCount());
    assertEquals(counts[i++], exec.getRecordCount());
  }

  if(context.getFailureCause() != null) {
    throw context.getFailureCause();
  }
  assertTrue(!context.isFailed());
}
项目:flume-release-1.7.0    文件:TestIntegration.java   
@Before
public void setup() {
  baseDir = Files.createTempDir();
  checkpointDir = new File(baseDir, "chkpt");
  Assert.assertTrue(checkpointDir.mkdirs() || checkpointDir.isDirectory());
  dataDirs = new File[3];
  dataDir = "";
  for (int i = 0; i < dataDirs.length; i++) {
    dataDirs[i] = new File(baseDir, "data" + (i + 1));
    Assert.assertTrue(dataDirs[i].mkdirs() || dataDirs[i].isDirectory());
    dataDir += dataDirs[i].getAbsolutePath() + ",";
  }
  dataDir = dataDir.substring(0, dataDir.length() - 1);
}
项目:hype    文件:ZipFiles.java   
/**
 * Private helper function for zipping files. This one goes recursively
 * through the input directory and all of its subdirectories and adds the
 * single zip entries.
 *
 * @param inputFile the file or directory to be added to the zip file
 * @param directoryName the string-representation of the parent directory
 *     name. Might be an empty name, or a name containing multiple directory
 *     names separated by "/". The directory name must be a valid name
 *     according to the file system limitations. The directory name should be
 *     empty or should end in "/".
 * @param zos the zipstream to write to
 * @throws IOException the zipping failed, e.g. because the output was not
 *     writeable.
 */
private static void zipDirectoryInternal(
    File inputFile,
    String directoryName,
    ZipOutputStream zos) throws IOException {
  String entryName = directoryName + inputFile.getName();
  if (inputFile.isDirectory()) {
    entryName += "/";

    // We are hitting a sub-directory. Recursively add children to zip in deterministic,
    // sorted order.
    File[] childFiles = inputFile.listFiles();
    if (childFiles.length > 0) {
      Arrays.sort(childFiles);
      // loop through the directory content, and zip the files
      for (File file : childFiles) {
        zipDirectoryInternal(file, entryName, zos);
      }

      // Since this directory has children, exit now without creating a zipentry specific to
      // this directory. The entry for a non-entry directory is incompatible with certain
      // implementations of unzip.
      return;
    }
  }

  // Put the zip-entry for this file or empty directory into the zipoutputstream.
  ZipEntry entry = new ZipEntry(entryName);
  entry.setTime(inputFile.lastModified());
  zos.putNextEntry(entry);

  // Copy file contents into zipoutput stream.
  if (inputFile.isFile()) {
    Files.asByteSource(inputFile).copyTo(zos);
  }
}
项目:flume-release-1.7.0    文件:TestResettableFileInputStream.java   
private static List<String> multiLineFileInit(File file, Charset charset)
    throws IOException {
  List<String> lines = Lists.newArrayList();
  lines.add("1. On the planet of Mars\n");
  lines.add("2. They have clothes just like ours,\n");
  lines.add("3. And they have the same shoes and same laces,\n");
  lines.add("4. And they have the same charms and same graces...\n");
  StringBuilder sb = new StringBuilder();
  for (String line : lines) {
    sb.append(line);
  }
  Files.write(sb.toString().getBytes(charset), file);
  return lines;
}
项目:circus-train    文件:CircusTrainTest.java   
@Test
public void twoYmlFiles() throws Exception {
  exit.expectSystemExitWithStatus(0);
  File ymlFile1 = temp.newFile("test-application1.yml");
  File ymlFile2 = temp.newFile("test-application2.yml");

  List<String> lines = ImmutableList
      .<String> builder()
      .add("source-catalog:")
      .add("  name: source")
      .add("  configuration-properties:")
      .add("    " + ConfVars.METASTOREURIS.varname + ": " + hive.getThriftConnectionUri())
      .add("replica-catalog:")
      .add("  name: replica")
      .add("  hive-metastore-uris: " + hive.getThriftConnectionUri())
      .build();
  Files.asCharSink(ymlFile1, UTF_8).writeLines(lines);

  lines = ImmutableList
      .<String> builder()
      .add("table-replications:")
      .add("  -")
      .add("    source-table:")
      .add("      database-name: " + DATABASE)
      .add("      table-name: source_" + TABLE)
      .add("    replica-table:")
      .add("      table-name: replica_" + TABLE)
      .add("      table-location: " + temp.newFolder("replica"))
      .build();
  Files.asCharSink(ymlFile2, UTF_8).writeLines(lines);

  exit.checkAssertionAfterwards(new Assertion() {
    @Override
    public void checkAssertion() throws Exception {
      assertTrue(hive.client().tableExists(DATABASE, "replica_" + TABLE));
    }
  });

  CircusTrain.main(new String[] { "--config=" + ymlFile1.getAbsolutePath() + "," + ymlFile2.getAbsolutePath() });
}
项目:filestack-java    文件:TestTransforms.java   
@Test
public void testAvTransform() throws Exception {
  ClassLoader loader = Thread.currentThread().getContextClassLoader();
  String oggPath = loader.getResource("com/filestack/sample_music.ogg").getPath();
  File oggFile = new File(oggPath);

  FileLink oggFileLink = client.upload(oggPath, false);
  HANDLES.add(oggFileLink.getHandle());

  AvTransformOptions options = new AvTransformOptions.Builder()
      .preset("mp3")
      .build();

  AvTransform transform = oggFileLink.avTransform(options);

  FileLink mp3FileLink;
  while ((mp3FileLink = transform.getFileLink()) == null) {
    Thread.sleep(5 * 1000);
  }
  HANDLES.add(mp3FileLink.getHandle());

  String mp3Path = loader.getResource("com/filestack/sample_music.mp3").getPath();
  File mp3File = new File(mp3Path);

  String correct = Files.asByteSource(mp3File).hash(Hashing.sha256()).toString();
  byte[] bytes = mp3FileLink.getContent().bytes();
  String output = Hashing.sha256().hashBytes(bytes).toString();

  Assert.assertEquals(correct, output);
}
项目:datarouter    文件:CopyFileConfigStrategy.java   
@Override
public void configure(String configDirectory){
    File sourceFile = new File(sourceFileLocation);
    File destinationFile = new File(configDirectory + "/" + destinationFileName);
    if(destinationFile.exists()){
        logger.warn("replacing {} with {}", destinationFile.getAbsolutePath(), sourceFile.getAbsolutePath());
    }else{
        logger.warn("creating {} from {}", destinationFile.getAbsolutePath(), sourceFile.getAbsolutePath());
    }
    try{
        Files.copy(sourceFile, destinationFile);
    }catch(IOException e){
        throw new RuntimeException(e);
    }
}
项目:BaseClient    文件:PlayerProfileCache.java   
/**
 * Load the cached profiles from disk
 */
public void load()
{
    BufferedReader bufferedreader = null;

    try
    {
        bufferedreader = Files.newReader(this.usercacheFile, Charsets.UTF_8);
        List<PlayerProfileCache.ProfileEntry> list = (List)this.gson.fromJson((Reader)bufferedreader, TYPE);
        this.usernameToProfileEntryMap.clear();
        this.uuidToProfileEntryMap.clear();
        this.gameProfiles.clear();

        for (PlayerProfileCache.ProfileEntry playerprofilecache$profileentry : Lists.reverse(list))
        {
            if (playerprofilecache$profileentry != null)
            {
                this.addEntry(playerprofilecache$profileentry.getGameProfile(), playerprofilecache$profileentry.getExpirationDate());
            }
        }
    }
    catch (FileNotFoundException var9)
    {
        ;
    }
    catch (JsonParseException var10)
    {
        ;
    }
    finally
    {
        IOUtils.closeQuietly((Reader)bufferedreader);
    }
}
项目:Reer    文件:JavaInstallationProbe.java   
private EnumMap<SysProp, String> getMetadataInternal(File jdkPath) {
    JavaExecAction exec = factory.newJavaExecAction();
    exec.executable(javaExe(jdkPath, "java"));
    File workingDir = Files.createTempDir();
    exec.setWorkingDir(workingDir);
    exec.setClasspath(new SimpleFileCollection(workingDir));
    try {
        writeProbe(workingDir);
        exec.setMain(JavaProbe.CLASSNAME);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        exec.setStandardOutput(baos);
        ByteArrayOutputStream errorOutput = new ByteArrayOutputStream();
        exec.setErrorOutput(errorOutput);
        exec.setIgnoreExitValue(true);
        ExecResult result = exec.execute();
        int exitValue = result.getExitValue();
        if (exitValue == 0) {
            return parseExecOutput(baos.toString());
        }
        return error("Command returned unexpected result code: " + exitValue + "\nError output:\n" + errorOutput);
    } catch (ExecException ex) {
        return error(ex.getMessage());
    } finally {
        try {
            FileUtils.deleteDirectory(workingDir);
        } catch (IOException e) {
            throw new GradleException("Unable to delete temp directory", e);
        }
    }
}
项目:Reer    文件:TestScenarioSelector.java   
private void addToScenarioList(String testId, Set<String> templates, File scenarioList, ResultsStore resultsStore) {
    try {
        long estimatedRuntime = getEstimatedRuntime(testId, resultsStore);
        List<String> args = Lists.newArrayList();
        args.add(testId);
        args.add(String.valueOf(estimatedRuntime));
        args.addAll(templates);
        Files.touch(scenarioList);
        Files.append(Joiner.on(';').join(args) + '\n', scenarioList, Charsets.UTF_8);
    } catch (IOException e) {
        throw new RuntimeException("Could not write to scenario list at " + scenarioList, e);
    }
}
项目:UltimateSpawn    文件:FileUtils.java   
/**
 * Move the specified file to the specified location.
 *
 * @param from The original file
 * @param to The destination file for the output
 */
public static void move(File from, File to) {
    try {
        Files.move(from, to);
    } catch (IOException e) {
        e.printStackTrace();
    }
}
项目:dremio-oss    文件:TestNewAggregateFunctions.java   
public void runTest(String physicalPlan, String inputDataFile,
    Object[] expected) throws Exception {
  try (ClusterCoordinator clusterCoordinator = LocalClusterCoordinator.newRunningCoordinator();
      SabotNode bit = new SabotNode(DEFAULT_SABOT_CONFIG, clusterCoordinator, CLASSPATH_SCAN_RESULT);
      DremioClient client = new DremioClient(DEFAULT_SABOT_CONFIG,
          clusterCoordinator)) {

    // run query.
    bit.run();
    client.connect();
    List<QueryDataBatch> results = client.runQuery(
        QueryType.PHYSICAL,
        Files.toString(FileUtils.getResourceAsFile(physicalPlan),
            Charsets.UTF_8).replace("#{TEST_FILE}",
            inputDataFile));

    try(RecordBatchLoader batchLoader = new RecordBatchLoader(bit
        .getContext().getAllocator())) {

      QueryDataBatch batch = results.get(1);
      assertTrue(batchLoader.load(batch.getHeader().getDef(),
          batch.getData()));

      int i = 0;
      for (VectorWrapper<?> v : batchLoader) {
        ValueVector.Accessor accessor = v.getValueVector().getAccessor();
        System.out.println((accessor.getObject(0)));
        assertEquals(expected[i++], (accessor.getObject(0)));
      }
    }
    for (QueryDataBatch b : results) {
      b.release();
    }
  }
}
项目:QDrill    文件:TestTraceMultiRecordBatch.java   
@Test
public void testFilter(@Injectable final DrillbitContext bitContext, @Injectable UserClientConnection connection) throws Throwable {
  new NonStrictExpectations() {{
    bitContext.getMetrics(); result = new MetricRegistry();
    bitContext.getAllocator(); result = RootAllocatorFactory.newRoot(c);
    bitContext.getConfig(); result = c;
    bitContext.getOperatorCreatorRegistry(); result = new OperatorCreatorRegistry(c);
    bitContext.getCompiler(); result = CodeCompiler.getTestCompiler(c);
  }};

  final PhysicalPlanReader reader = new PhysicalPlanReader(c, c.getMapper(), CoordinationProtos.DrillbitEndpoint.getDefaultInstance());
  final PhysicalPlan plan = reader.readPhysicalPlan(Files.toString(FileUtils.getResourceAsFile("/trace/multi_record_batch_trace.json"), Charsets.UTF_8));
  final FunctionImplementationRegistry registry = new FunctionImplementationRegistry(c);
  final FragmentContext context = new FragmentContext(bitContext, PlanFragment.getDefaultInstance(), connection, registry);
  final SimpleRootExec exec = new SimpleRootExec(ImplCreator.getExec(context, (FragmentRoot) plan.getSortedOperators(false).iterator().next()));

  while(exec.next()) {
    for(final ValueVector vv: exec){
      vv.clear();
    }
  }

  exec.close();

  if(context.getFailureCause() != null) {
    throw context.getFailureCause();
  }
  assertTrue(!context.isFailed());
}
项目:Reer    文件:FileCollectionBackedTextResource.java   
public Reader asReader() {
    File file = asFile();
    try {
        return Files.newReader(asFile(), charset);
    } catch (FileNotFoundException e) {
        throw ResourceExceptions.readMissing(file, e);
    }
}
项目:Reer    文件:FileCollectionBackedArchiveTextResource.java   
public FileCollectionBackedArchiveTextResource(final FileOperations fileOperations,
                                               final TemporaryFileProvider tempFileProvider,
                                               final FileCollection fileCollection,
                                               final String path, Charset charset) {
    super(tempFileProvider, new LazilyInitializedFileCollection() {
        @Override
        public String getDisplayName() {
            return String.format("entry '%s' in archive %s", path, fileCollection);
        }

        @Override
        public FileCollection createDelegate() {
            File archiveFile = fileCollection.getSingleFile();
            String fileExtension = Files.getFileExtension(archiveFile.getName());
            FileTree archiveContents = fileExtension.equals("jar") || fileExtension.equals("zip")
                ? fileOperations.zipTree(archiveFile) : fileOperations.tarTree(archiveFile);
            PatternSet patternSet = new PatternSet();
            patternSet.include(path);
            return archiveContents.matching(patternSet);
        }

        @Override
        public void visitDependencies(TaskDependencyResolveContext context) {
            context.add(fileCollection);
        }
    }, charset);
}