org.jboss.shrinkwrap.api.Archive.addAsDirectories()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(9.4k)|赞(0)|评价(0)|浏览(140)

本文整理了Java中org.jboss.shrinkwrap.api.Archive.addAsDirectories()方法的一些代码示例,展示了Archive.addAsDirectories()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Archive.addAsDirectories()方法的具体详情如下:
包路径:org.jboss.shrinkwrap.api.Archive
类名称:Archive
方法名:addAsDirectories

Archive.addAsDirectories介绍

[英]Adds the specified directories.
[中]添加指定的目录。

代码示例

代码示例来源:origin: wildfly/wildfly-arquillian

@Override
public T addAsDirectories(final String... paths) throws IllegalArgumentException {
  return delegate.addAsDirectories(paths);
}

代码示例来源:origin: wildfly/wildfly-arquillian

@Override
public T addAsDirectories(final ArchivePath... paths) throws IllegalArgumentException {
  return delegate.addAsDirectories(paths);
}

代码示例来源:origin: org.jboss.shrinkwrap/shrinkwrap-impl-base

/**
 * {@inheritDoc}
 *
 * @see org.jboss.shrinkwrap.api.Archive#addAsDirectories(org.jboss.shrinkwrap.api.ArchivePath[])
 */
@Override
public T addAsDirectories(ArchivePath... paths) throws IllegalArgumentException {
  this.getArchive().addAsDirectories(paths);
  return covarientReturn();
}

代码示例来源:origin: org.jboss.shrinkwrap/shrinkwrap-impl-base

/**
 * {@inheritDoc}
 *
 * @see org.jboss.shrinkwrap.api.Archive#addAsDirectories(java.lang.String[])
 */
@Override
public T addAsDirectories(String... paths) throws IllegalArgumentException {
  this.getArchive().addAsDirectories(paths);
  return covarientReturn();
}

代码示例来源:origin: shrinkwrap/shrinkwrap

/**
 * {@inheritDoc}
 *
 * @see org.jboss.shrinkwrap.api.Archive#addAsDirectories(org.jboss.shrinkwrap.api.ArchivePath[])
 */
@Override
public T addAsDirectories(ArchivePath... paths) throws IllegalArgumentException {
  this.getArchive().addAsDirectories(paths);
  return covarientReturn();
}

代码示例来源:origin: shrinkwrap/shrinkwrap

/**
 * {@inheritDoc}
 *
 * @see org.jboss.shrinkwrap.api.Archive#addAsDirectories(java.lang.String[])
 */
@Override
public T addAsDirectories(String... paths) throws IllegalArgumentException {
  this.getArchive().addAsDirectories(paths);
  return covarientReturn();
}

代码示例来源:origin: org.jboss.shrinkwrap/shrinkwrap-impl-nio2

/**
 * {@inheritDoc}
 *
 * @see java.nio.file.spi.FileSystemProvider#createDirectory(java.nio.file.Path,
 *      java.nio.file.attribute.FileAttribute<?>[])
 */
@Override
public void createDirectory(final Path dir, final FileAttribute<?>... attrs) throws IOException {
  final Archive<?> archive = this.getArchive(dir);
  final ArchivePath parent = ArchivePaths.create(dir.toString()).getParent();
  if (parent != null && !archive.contains(parent)) {
    // IOException? Despite being a stupid choice for this, it's what the NIO.2 API uses.
    throw new IOException("Cannot recursively create parent directories for: " + dir
      + "; instead invoke \"createDirectories\"");
  }
  archive.addAsDirectories(dir.toString());
  if (log.isLoggable(Level.FINEST)) {
    log.finest("Created directory " + dir.toString() + " on " + archive.toString());
  }
}

代码示例来源:origin: shrinkwrap/shrinkwrap

/**
 * {@inheritDoc}
 *
 * @see java.nio.file.spi.FileSystemProvider#createDirectory(java.nio.file.Path,
 *      java.nio.file.attribute.FileAttribute<?>[])
 */
@Override
public void createDirectory(final Path dir, final FileAttribute<?>... attrs) throws IOException {
  final Archive<?> archive = this.getArchive(dir);
  final ArchivePath parent = ArchivePaths.create(dir.toString()).getParent();
  if (parent != null && !archive.contains(parent)) {
    // IOException? Despite being a stupid choice for this, it's what the NIO.2 API uses.
    throw new IOException("Cannot recursively create parent directories for: " + dir
      + "; instead invoke \"createDirectories\"");
  }
  archive.addAsDirectories(dir.toString());
  if (log.isLoggable(Level.FINEST)) {
    log.finest("Created directory " + dir.toString() + " on " + archive.toString());
  }
}

代码示例来源:origin: shrinkwrap/shrinkwrap

@Test
public void createTempDirectory() throws IOException {
  final String tempDir = "/tmp";
  this.getArchive().addAsDirectories(tempDir);
  final String prefix = "prefix";
  final Path tempDirPath = fs.getPath(tempDir);
  final Path newPath = Files.createTempDirectory(tempDirPath, prefix, new FileAttribute<?>[] {});
  Assert.assertTrue("temp dir name was not in expected form",
    newPath.toString().startsWith(tempDir + "/" + prefix));
}

代码示例来源:origin: shrinkwrap/shrinkwrap

@Test
public void copyFromInputStreamToExistingDirectory() throws IOException {
  final InputStream in = new ByteArrayInputStream("test".getBytes("UTF-8"));
  final String pathName = "directory";
  final Path path = fs.getPath(pathName);
  // Add some directory to the archive
  this.getArchive().addAsDirectories(pathName);
  // Now try to copy to the same path as the dir
  boolean gotException = false;
  try {
    Files.copy(in, path);
  } catch (final FileAlreadyExistsException faee) {
    gotException = true;
  }
  Assert.assertTrue("Overwrite of existing directory should fail", gotException);
}

代码示例来源:origin: shrinkwrap/shrinkwrap

@Test
public void isDirectoryTrue() throws IOException {
  this.getArchive().addAsDirectories("path");
  Assert.assertTrue(Files.isDirectory(fs.getPath("path"), (LinkOption) null));
}

代码示例来源:origin: shrinkwrap/shrinkwrap

@Test
public void copyFromDirectoryPathToOutputStream() throws IOException {
  // Populate the archive w/ content
  final String path = "dirPath";
  this.getArchive().addAsDirectories(path);
  // Attempt to copy the dir
  final ByteArrayOutputStream out = new ByteArrayOutputStream();
  boolean gotException = false;
  try {
    Files.copy(fs.getPath(path), out);
  } catch (final IllegalArgumentException iae) {
    gotException = true;
  }
  Assert.assertTrue("Call to copy a directory contents to an outstream should not succeed", gotException);
}

代码示例来源:origin: shrinkwrap/shrinkwrap

@Test
public void copyFromInputStreamToExistingNonEmptyDirectoryWithReplaceExistingOption() throws IOException {
  final InputStream in = new ByteArrayInputStream("test".getBytes("UTF-8"));
  final String dir = "/directory";
  final String subdir = dir + "/subdir";
  final Path dirPath = fs.getPath(dir);
  // Add some nested directory to the archive
  this.getArchive().addAsDirectories(subdir);
  // Now try to copy to a nonempty dir
  boolean gotException = false;
  try {
    Files.copy(in, dirPath, StandardCopyOption.REPLACE_EXISTING);
  } catch (final DirectoryNotEmptyException dnee) {
    gotException = true;
  }
  Assert.assertTrue("Overwrite of existing non-empty dir should fail, even with replace option", gotException);
}

代码示例来源:origin: shrinkwrap/shrinkwrap

@Test
public void newDirectoryStream() throws IOException {
  final String dirs = "a/b/c/d/e";
  this.getArchive().addAsDirectories(dirs);
  final DirectoryStream<Path> stream = Files.newDirectoryStream(fs.getPath("/"));
  final Iterator<Path> paths = stream.iterator();
  int counter = 0;
  while (paths.hasNext()) {
    counter++;
    final Path path = paths.next();
    Assert.assertTrue(this.getArchive().contains(path.toString()));
  }
  Assert.assertEquals(1, counter);
}

代码示例来源:origin: shrinkwrap/shrinkwrap

/**
 * SHRINKWRAP-416
 */
@Test
public void addResourceToExistingDirThrowsIllegalOverwriteException() {
  // Create the new archive
  final Archive<?> archive = createNewArchive();
  // Put in an asset
  final ArchivePath path = ArchivePaths.create("testPath");
  archive.addAsDirectories(path);
  // Now try again with a new asset, and this should fail
  try {
    archive.add(new StringAsset("failContent"), path);
  } catch (final IllegalOverwriteException ioe) {
    // Good
    return;
  }
  // Fail us
  TestCase.fail("Expected " + IllegalOverwriteException.class.getName() + " not received");
}

代码示例来源:origin: shrinkwrap/shrinkwrap

@Test
public void testHandlerIsCalledWhenAddingDirectoriesWithStringPath() throws Exception {
  final SimpleHandler simpleHandler1 = new SimpleHandler();
  final SimpleHandler simpleHandler2 = new SimpleHandler();
  getArchive().addHandlers(simpleHandler1, simpleHandler2);
  getArchive().addAsDirectories("/path/to/dir1");
  Assert.assertTrue("Handler not called", simpleHandler1.called);
  Assert.assertTrue("Handler not called", simpleHandler2.called);
}

代码示例来源:origin: shrinkwrap/shrinkwrap

@Test
public void testHandlerIsCalledWhenAddingDirectoriesWithArchivePath() throws Exception {
  final SimpleHandler simpleHandler1 = new SimpleHandler();
  final SimpleHandler simpleHandler2 = new SimpleHandler();
  getArchive().addHandlers(simpleHandler1, simpleHandler2);
  getArchive().addAsDirectories(ArchivePaths.create("/path/to/dir1"));
  Assert.assertTrue("Handler not called", simpleHandler1.called);
  Assert.assertTrue("Handler not called", simpleHandler2.called);
}

代码示例来源:origin: shrinkwrap/shrinkwrap

/**
 * Delete directory which contains children.
 */
@Test
public void testDeletePathWithChildren() {
  // given
  final Archive<T> archive = getArchive();
  final String dirName = "dir";
  archive.addAsDirectories(dirName);
  archive.add(new StringAsset("asset"), dirName, "abc.txt").add(new StringAsset("asset"), dirName, "cde.txt");
  archive.add(new StringAsset("other"), "other.txt");
  // when
  archive.delete("dir");
  // then
  Assert.assertFalse(archive.contains(dirName));
  Assert.assertEquals(1, archive.getContent().size());
}

代码示例来源:origin: shrinkwrap/shrinkwrap

/**
 * Tests that empty directories may be added to the archive
 *
 * @throws Exception
 */
@Test
public void testAddEmptyDirectories() throws Exception {
  Archive<T> archive = getArchive();
  // Get Paths to add
  final ArchivePath path1 = ArchivePaths.create("path/to/dir");
  final ArchivePath path2 = ArchivePaths.create("path/to/dir2");
  final ArchivePath path3 = ArchivePaths.create("path/to");
  // Add
  archive.addAsDirectories(path1, path2, path3);
  // Test
  final String message = "Should be able to add directory: ";
  Assert.assertTrue(message + path1, archive.contains(path1));
  Assert.assertTrue(message + path2, archive.contains(path2));
  Assert.assertTrue(message + path3, archive.contains(path3));
}

相关文章