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


Java MoreFiles类代码示例

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


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

示例1: readFromPath

import com.google.common.io.MoreFiles; //导入依赖的package包/类
/** Returns the application info read from either an app folder or ipa archive */
public static IosAppInfo readFromPath(Path ipaOrAppPath) throws IOException {
  NSObject plistDict;
  if (Files.isDirectory(ipaOrAppPath)) {
    plistDict = PlistParser.fromPath(ipaOrAppPath.resolve("Info.plist"));
  } else {
    try (FileSystem ipaFs = FileSystems.newFileSystem(ipaOrAppPath, null)) {
      Path appPath =
          MoreFiles.listFiles(ipaFs.getPath("Payload"))
              .stream()
              // Can't use Files.isDirectory, because no entry is a "directory" in a zip.
              .filter(e -> e.toString().endsWith(".app/"))
              .collect(MoreCollectors.onlyElement());
      plistDict = PlistParser.fromPath(appPath.resolve("Info.plist"));
    }
  }
  return readFromPlistDictionary((NSDictionary) plistDict);
}
 
开发者ID:google,项目名称:ios-device-control,代码行数:19,代码来源:IosAppInfo.java

示例2: listSystemApps

import com.google.common.io.MoreFiles; //导入依赖的package包/类
static ImmutableSet<IosAppInfo> listSystemApps(String productVersion) throws IOException {
  try {
    return runtime2SystemApps.computeIfAbsent(
        productVersion,
        r ->
            tunnel(
                () -> {
                  Path appsDir = runtimeRootPath(productVersion).resolve("Applications");
                  return MoreFiles.listFiles(appsDir)
                      .stream()
                      .filter(p -> Files.exists(p.resolve("Info.plist")))
                      .map(a -> tunnel(() -> IosAppInfo.readFromPath(a)))
                      .collect(toImmutableSet());
                }));
  } catch (TunnelException e) {
    throw e.getCauseAs(IOException.class);
  }
}
 
开发者ID:google,项目名称:ios-device-control,代码行数:19,代码来源:SimulatorDeviceHost.java

示例3: installApplication

import com.google.common.io.MoreFiles; //导入依赖的package包/类
@Override
public void installApplication(Path ipaOrAppPath) throws IosDeviceException {
  try {
    if (Files.isDirectory(ipaOrAppPath)) {
      await(simctl.install(ipaOrAppPath.toString()));
    } else {
      Path tmpDir = Files.createTempDirectory("app");
      try {
        unzipFile(ipaOrAppPath, tmpDir);
        Path appPath =
            tmpDir
                .resolve("Payload")
                .resolve(MoreFiles.getNameWithoutExtension(ipaOrAppPath) + ".app");
        await(simctl.install(appPath.toString()));
      } finally {
        MoreFiles.deleteRecursively(tmpDir, RecursiveDeleteOption.ALLOW_INSECURE);
      }
    }
  } catch (IOException e) {
    throw new IosDeviceException(this, e);
  }
}
 
开发者ID:google,项目名称:ios-device-control,代码行数:23,代码来源:SimulatorDeviceImpl.java

示例4: writeFile

import com.google.common.io.MoreFiles; //导入依赖的package包/类
public static Single<WriteFileEvent> writeFile(final String content, final Path path, final boolean overwrite) {
    Preconditions.checkNotNull(content);
    Preconditions.checkNotNull(path);
    return Single.fromCallable(() -> {
        if (path.getParent() != null && !Files.exists(path.getParent())) {
            Files.createDirectories(path.getParent());
        }
        if (overwrite) {
            Files.deleteIfExists(path);
        } else if (Files.isDirectory(path)) {
            throw new IOException("There is already a directory at " + path);
        } else if (Files.exists(path)) {
            throw new IOException("There is already a file at " + path);
        }
        final ByteSink sink = MoreFiles.asByteSink(path);
        sink.write(content.getBytes());
        return WriteFileEvent.of(path);
    }).subscribeOn(Schedulers.io());
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:20,代码来源:CommonTasks.java

示例5: testCachingFile

import com.google.common.io.MoreFiles; //导入依赖的package包/类
public void testCachingFile() throws IOException {
  // Setup environment.
  String expectedContent = "// content content content";
  String newExpectedContent = "// new content new content new content";
  Path jsFile = Files.createTempFile("test", ".js");
  MoreFiles.asCharSink(jsFile, StandardCharsets.UTF_8).write(expectedContent);
  SourceFile sourceFile = SourceFile.fromFile(jsFile.toFile());

  // Verify initial state.
  assertEquals(expectedContent, sourceFile.getCode());

  // Perform a change.
  MoreFiles.asCharSink(jsFile, StandardCharsets.UTF_8).write(newExpectedContent);
  sourceFile.clearCachedSource();

  // Verify final state.
  assertEquals(newExpectedContent, sourceFile.getCode());
}
 
开发者ID:google,项目名称:closure-compiler,代码行数:19,代码来源:SourceFileTest.java

示例6: createStatements

import com.google.common.io.MoreFiles; //导入依赖的package包/类
private List<StatementFileExporter> createStatements(LSql lSql, JavaExporter javaExporter, CliArgs cliArgs) {
    List<StatementFileExporter> list = newLinkedList();

    if (cliArgs.getSqlStatements() != null) {
        Path statementRootDir = new File(cliArgs.getSqlStatements()).toPath();
        Iterable<Path> children = MoreFiles.directoryTreeTraverser().preOrderTraversal(statementRootDir);
        for (Path child : children) {
            File file = child.toFile();
            if (file.isFile() && file.getName().endsWith(".sql")) {
                StatementFileExporter statementFileExporter =
                        new StatementFileExporter(lSql, javaExporter, file, cliArgs.getSqlStatements());

                list.add(statementFileExporter);
            }
        }
    }

    return list;
}
 
开发者ID:w11k,项目名称:lsql,代码行数:20,代码来源:Main.java

示例7: cleanUp

import com.google.common.io.MoreFiles; //导入依赖的package包/类
@After
public void cleanUp() throws Exception {
    appContext.stopLogging();
    DataStore.closeConnection(dbconn);
    try {
        MoreFiles
            .deleteRecursively(Paths.get(DataStore.getDbDir(testDbName)), RecursiveDeleteOption.ALLOW_INSECURE);
    } catch (IOException e) {
        // DONT make test failure.
        System.err.println("test db clean-up failure, remove manually later :P");
        e.printStackTrace();
    }
}
 
开发者ID:SecureSkyTechnology,项目名称:burpextender-proxyhistory-webui,代码行数:14,代码来源:AppContextTest.java

示例8: close

import com.google.common.io.MoreFiles; //导入依赖的package包/类
@Override
public void close() {
    try {
        MoreFiles.deleteRecursively(fProjectPath);
    } catch (IOException e) {
    }
}
 
开发者ID:lttng,项目名称:lttng-scope,代码行数:8,代码来源:StubProject.java

示例9: stopService

import com.google.common.io.MoreFiles; //导入依赖的package包/类
private void stopService() {
    try {
        brokerService.stop();
        MoreFiles.deleteRecursively(tempDir.toPath(), RecursiveDeleteOption.ALLOW_INSECURE);
        brokerService = null;
    } catch (Exception e) {
        throw new IllegalStateException("Could not stop broker", e);
    }
}
 
开发者ID:zapodot,项目名称:embedded-jms-junit,代码行数:10,代码来源:EmbeddedJmsRuleImpl.java

示例10: clearCrashLogs

import com.google.common.io.MoreFiles; //导入依赖的package包/类
@Override
public void clearCrashLogs() throws IosDeviceException {
  try {
    Path tempDir = Files.createTempDirectory("artifacts");
    try {
      idevice.crashreport(tempDir.toString());
    } finally {
      MoreFiles.deleteRecursively(tempDir, RecursiveDeleteOption.ALLOW_INSECURE);
    }
  } catch (IOException e) {
    throw new IosDeviceException(this, e);
  }
}
 
开发者ID:google,项目名称:ios-device-control,代码行数:14,代码来源:RealDeviceImpl.java

示例11: toModel

import com.google.common.io.MoreFiles; //导入依赖的package包/类
private static IosModel toModel(String deviceType) throws IOException {
  checkArgument(deviceType.matches("[-\\w]*"));
  Path profileInfoBasePath =
      Paths.get(
          "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/"
              + "Developer/Library/CoreSimulator/Profiles/DeviceTypes");
  Path deviceTypePath =
      MoreFiles.listFiles(profileInfoBasePath)
          .stream()
          // The directory name that matches a given device type is the same as the name from the
          // device.plist file, with the hyphens replaced with spaces, hyphens, parentheses or
          // periods
          .filter(
              p -> MoreFiles.getNameWithoutExtension(p).replaceAll("\\W", "-").equals(deviceType))
          .collect(MoreCollectors.onlyElement());
  String rawProductName = MoreFiles.getNameWithoutExtension(deviceTypePath);
  String productName = GENERATION_PATTERN.matcher(rawProductName).replaceFirst("$1");

  Path profilePath = deviceTypePath.resolve("Contents/Resources/profile.plist");
  NSDictionary profileDict = (NSDictionary) PlistParser.fromPath(profilePath);
  String identifier = profileDict.get("modelIdentifier").toString();

  NSArray supportedArchs = (NSArray) profileDict.get("supportedArchs");
  // The supported architecture can either be just i386 or i386 and x86_64. The
  // actual architecture will be x86_64 if its supported, or i386 otherwise.
  Architecture architecture =
      supportedArchs.containsObject(Architecture.X86_64.toString())
          ? Architecture.X86_64
          : Architecture.I386;
  return IosModel.builder()
      .identifier(identifier)
      .productName(productName)
      .architecture(architecture)
      .build();
}
 
开发者ID:google,项目名称:ios-device-control,代码行数:36,代码来源:SimulatorDeviceHost.java

示例12: userApps

import com.google.common.io.MoreFiles; //导入依赖的package包/类
private ImmutableSet<IosAppInfo> userApps() throws IOException {
  Path appPath =
      Paths.get(
          System.getProperty("user.home"),
          "Library/Developer/CoreSimulator/Devices",
          udid,
          "data/Containers/Bundle/Application");
  if (!Files.exists(appPath)) {
    return ImmutableSet.of();
  }
  try {
    return MoreFiles.listFiles(appPath)
        .stream()
        .map(
            p ->
                tunnel(
                    () ->
                        MoreFiles.listFiles(p)
                            .stream()
                            .filter(a -> MoreFiles.getFileExtension(a).equals("app"))
                            .collect(MoreCollectors.onlyElement())))
        .map(a -> tunnel(() -> IosAppInfo.readFromPath(a)))
        .collect(toImmutableSet());
  } catch (TunnelException e) {
    throw e.getCauseAs(IOException.class);
  }
}
 
开发者ID:google,项目名称:ios-device-control,代码行数:28,代码来源:SimulatorDeviceImpl.java

示例13: emptyProject

import com.google.common.io.MoreFiles; //导入依赖的package包/类
@Test
public void emptyProject() throws Exception {

    final FileSystem fs = Jimfs.newFileSystem();

    // Workaround: JimFs does not implement .toFile;
    // We clone and fail buckaroo-recipes if it does not exist, so we create it.
    MoreFiles.createParentDirectories(fs.getPath(
        System.getProperty("user.home"),
        ".buckaroo",
        "buckaroo-recipes",
        ".git"));

    final Project project = Project.of();

    EvenMoreFiles.writeFile(
        fs.getPath("buckaroo.json"),
        Serializers.serialize(project));

    final Observable<Event> task = ResolveTasks.resolveDependenciesInWorkingDirectory(fs);

    task.toList().blockingGet();

    assertEquals(
        right(DependencyLocks.of()),
        Serializers.parseDependencyLocks(EvenMoreFiles.read(fs.getPath("buckaroo.lock.json"))));
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:28,代码来源:ResolveTasksTest.java

示例14: installDirectlyFromGitHub1

import com.google.common.io.MoreFiles; //导入依赖的package包/类
@Test
public void installDirectlyFromGitHub1() throws Exception {

    final FileSystem fs = Jimfs.newFileSystem();

    // Workaround: JimFs does not implement .toFile;
    // We clone and fail buckaroo-recipes if it does not exist, so we create it.
    MoreFiles.createParentDirectories(fs.getPath(
        System.getProperty("user.home"),
        ".buckaroo",
        "buckaroo-recipes",
        ".git"));

    final ImmutableList<PartialDependency> partialDependencies = ImmutableList.of(
        PartialDependency.of(
            Identifier.of("github"),
            Identifier.of("njlr"),
            Identifier.of("test-lib-a"),
            AnySemanticVersion.of()));

    InitTasks.initWorkingDirectory(fs).toList().blockingGet();

    final List<Event> events = InstallTasks.installDependencyInWorkingDirectory(fs, partialDependencies).toList().blockingGet();

    assertTrue(Files.exists(fs.getPath("BUCKAROO_DEPS")));

    final Path dependencyFolder = fs.getPath(
        "buckaroo", "github", "njlr", "test-lib-a");

    assertTrue(Files.exists(dependencyFolder.resolve("BUCK")));
    assertTrue(Files.exists(dependencyFolder.resolve("BUCKAROO_DEPS")));
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:33,代码来源:InstallTasksTest.java

示例15: installDirectlyFromGitHub2

import com.google.common.io.MoreFiles; //导入依赖的package包/类
@Test
public void installDirectlyFromGitHub2() throws Exception {

    final FileSystem fs = Jimfs.newFileSystem();

    // Workaround: JimFs does not implement .toFile;
    // We clone and fail buckaroo-recipes if it does not exist, so we create it.
    MoreFiles.createParentDirectories(fs.getPath(
        System.getProperty("user.home"),
        ".buckaroo",
        "buckaroo-recipes",
        ".git"));

    final ImmutableList<PartialDependency> partialDependencies = ImmutableList.of(
        PartialDependency.of(
            Identifier.of("github"),
            Identifier.of("njlr"),
            Identifier.of("test-lib-d"),
            AnySemanticVersion.of()));

    InitTasks.initWorkingDirectory(fs).toList().blockingGet();

    InstallTasks.installDependencyInWorkingDirectory(fs, partialDependencies).toList().blockingGet();

    assertTrue(Files.exists(fs.getPath("BUCKAROO_DEPS")));

    final Path dependencyFolder = fs.getPath(
        "buckaroo", "github", "njlr", "test-lib-d");

    assertTrue(Files.exists(dependencyFolder.resolve("BUCK")));
    assertTrue(Files.exists(dependencyFolder.resolve("BUCKAROO_DEPS")));
}
 
开发者ID:LoopPerfect,项目名称:buckaroo,代码行数:33,代码来源:InstallTasksTest.java


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