当前位置: 首页>>代码示例>>Java>>正文


Java Files类代码示例

本文整理汇总了Java中com.google.common.io.Files的典型用法代码示例。如果您正苦于以下问题:Java Files类的具体用法?Java Files怎么用?Java Files使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Files类属于com.google.common.io包,在下文中一共展示了Files类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: dumpsStepsReplacingAliases

import com.google.common.io.Files; //导入依赖的package包/类
@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));
}
 
开发者ID:hristo-vrigazov,项目名称:bromium,代码行数:26,代码来源:DslStepsDumperTest.java

示例2: shouldReload

import com.google.common.io.Files; //导入依赖的package包/类
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;
    }
}
 
开发者ID:OvercastNetwork,项目名称:ProjectAres,代码行数:17,代码来源:MapDefinition.java

示例3: readAll

import com.google.common.io.Files; //导入依赖的package包/类
@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);
        }
    };
}
 
开发者ID:papyrusglobal,项目名称:state-channels,代码行数:22,代码来源:FileBlockReader.java

示例4: readPrivateKey

import com.google.common.io.Files; //导入依赖的package包/类
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);
}
 
开发者ID:airlift,项目名称:drift,代码行数:25,代码来源:PemReader.java

示例5: finish

import com.google.common.io.Files; //导入依赖的package包/类
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));
}
 
开发者ID:isi-nlp,项目名称:tac-kbp-eal,代码行数:17,代码来源:ScoreKBPAgainstERE.java

示例6: complicatedSelfHost

import com.google.common.io.Files; //导入依赖的package包/类
@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");
}
 
开发者ID:jomof,项目名称:cmakeify,代码行数:23,代码来源:TestCmakeify.java

示例7: generate

import com.google.common.io.Files; //导入依赖的package包/类
@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);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:18,代码来源:SimpleTemplateOperation.java

示例8: saveHistory

import com.google.common.io.Files; //导入依赖的package包/类
/**
 * 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);
	}
}
 
开发者ID:Skyost,项目名称:SkyDocs,代码行数:19,代码来源:ProjectsFrame.java

示例9: verifyLimitCount

import com.google.common.io.Files; //导入依赖的package包/类
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());
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:20,代码来源:TestSimpleLimit.java

示例10: testLifecycle

import com.google.common.io.Files; //导入依赖的package包/类
@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());
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:27,代码来源:TestTaildirSource.java

示例11: initZkDnindex

import com.google.common.io.Files; //导入依赖的package包/类
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);
    }
}
 
开发者ID:actiontech,项目名称:dble,代码行数:20,代码来源:DbleServer.java

示例12: sqlite

import com.google.common.io.Files; //导入依赖的package包/类
@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);
}
 
开发者ID:jomof,项目名称:cdep,代码行数:18,代码来源:TestCDep.java

示例13: handleAndroidFile

import com.google.common.io.Files; //导入依赖的package包/类
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()));
}
 
开发者ID:FlowCI,项目名称:flow-platform,代码行数:23,代码来源:CredentialController.java

示例14: writeChanges

import com.google.common.io.Files; //导入依赖的package包/类
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);
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:17,代码来源:UserList.java

示例15: save

import com.google.common.io.Files; //导入依赖的package包/类
@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);
}
 
开发者ID:sinaa,项目名称:train-simulator,代码行数:18,代码来源:StatisticsController.java


注:本文中的com.google.common.io.Files类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。