org.glassfish.api.deployment.archive.WritableArchive类的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(12.5k)|赞(0)|评价(0)|浏览(142)

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

WritableArchive介绍

[英]Interface for implementing write access to an underlying archive on a unspecified medium
[中]用于在未指定介质上实现对底层归档文件的写访问的接口

代码示例

代码示例来源:origin: org.glassfish.deployment/deployment-common

/**
 * Close a previously returned sub archive
 *
 * @param subArchive output stream to close
 * @link Archive.getSubArchive}
 */
@Override
public void closeEntry(WritableArchive subArchive) throws IOException {
  subArchive.close();
}

代码示例来源:origin: org.glassfish.common/internal-api

DeploymentContext context) throws IOException {
Enumeration<String> e = source.entries();
while (e.hasMoreElements()) {
  String entryName = e.nextElement();
  InputStream is = new BufferedInputStream(source.getEntry(entryName));
  OutputStream os = null;
  try {
    os = target.putNextEntry(entryName);
    FileUtils.copy(is, os, source.getEntrySize(entryName));
  } finally {
    if (os!=null) {
      target.closeEntry();
Manifest m = source.getManifest();
if (m!=null) {
  OutputStream os  = target.putNextEntry(JarFile.MANIFEST_NAME);
  m.write(os);
  target.closeEntry();

代码示例来源:origin: org.glassfish.main.deployment/deployment-javaee-full

if (! subTarget.getURI().equals(subArchive.getURI())) {
if (expandedOriginalArchive.exists(moduleURI)) {
  final URI unexpandedSubArchiveURI = expandedOriginalArchive.getURI().resolve(moduleURI);
  return archiveFactory.openArchive(unexpandedSubArchiveURI);

代码示例来源:origin: org.glassfish.deployment/dol

/**
 * Copy this archivist to a new abstract archive
 *
 * @param source            the source archive to copy from
 * @param target            the target archive to copy to
 * @param entriesToSkip     the entries that will be skipped by target archive
 * @param overwriteManifest if true, the manifest in source archive
 *                          overwrites the one in target archive
 */
public void copyInto(ReadableArchive source, WritableArchive target,
           Vector entriesToSkip, boolean overwriteManifest)
    throws IOException {
  copyJarElements(source, target, entriesToSkip);
  if (overwriteManifest) {
    Manifest m = source.getManifest();
    if (m != null) {
      OutputStream os = target.putNextEntry(JarFile.MANIFEST_NAME);
      m.write(os);
      target.closeEntry();
    }
  }
}

代码示例来源:origin: org.glassfish.deployment/dol

/**
 * add a file to an output abstract archive
 *
 * @param archive abstraction to use when adding the file
 * @param filePath to the file to add
 * @param entryName the entry name in the archive
 */
protected static void addFileToArchive(WritableArchive archive, String filePath, String entryName)
    throws IOException {
  FileInputStream is = new FileInputStream(new File(filePath));
  OutputStream os = archive.putNextEntry(entryName);
  try {
    ArchivistUtils.copyWithoutClose(is, os);
  } finally {
    is.close();
    archive.closeEntry();
  }
}

代码示例来源:origin: org.glassfish.main.core/kernel

Enumeration<String> e = source.entries();
while (e.hasMoreElements()) {
  String entryName = e.nextElement();
    continue;
  InputStream sis = source.getEntry(entryName);
  if (sis != null) {
    InputStream is = new BufferedInputStream(sis);
    OutputStream os = null;
    try {
      os = target.putNextEntry(entryName);
      FileUtils.copy(is, os, source.getEntrySize(entryName));
    } finally {
      if (os!=null) {
        target.closeEntry();
if (m!=null) {
  processManifest(m, moduleName);
  OutputStream os  = target.putNextEntry(JarFile.MANIFEST_NAME);
  m.write(os);
  target.closeEntry();
source.close();
target.close();

代码示例来源:origin: org.glassfish.main.deployment/dol

for (ModuleDescriptor aModule : a.getModules()) {
  entriesAdded.add(aModule.getArchiveUri());
  ReadableArchive subSource = source.getSubArchive(aModule.getArchiveUri());
  WritableArchive subTarget = target.createSubArchive(aModule.getArchiveUri());
  Archivist newArchivist = archivistFactory.get().getArchivist(aModule.getModuleType());
  ReadableArchive subArchive = archiveFactory.openArchive(subTarget.getURI());
  subSource.setParentArchive(subArchive);
  newArchivist.copyInto(subSource, subTarget, overwriteManifest);
  target.closeEntry(subTarget);
  String subModulePath = subSource.getURI().getSchemeSpecificPart();
  String parentPath = source.getURI().getSchemeSpecificPart();
  if (subModulePath.startsWith(parentPath)) {

代码示例来源:origin: org.glassfish.deployment/dol

for (ModuleDescriptor aModule : a.getModules()) {
  entriesAdded.add(aModule.getArchiveUri());
  ReadableArchive subSource = source.getSubArchive(aModule.getArchiveUri());
  WritableArchive subTarget = target.createSubArchive(aModule.getArchiveUri());
  Archivist newArchivist = archivistFactory.get().getPrivateArchivistFor(aModule.getModuleType());
  newArchivist.copyInto(subSource, subTarget, overwriteManifest);
  target.closeEntry(subTarget);
  String subModulePath = subSource.getURI().getSchemeSpecificPart();
  String parentPath = source.getURI().getSchemeSpecificPart();
  if (subModulePath.startsWith(parentPath)) {
    subModulePath = subModulePath.substring(parentPath.length()+File.separator.length());

代码示例来源:origin: org.glassfish.deployment/dol

try {
  File outputFile=null;
  if (oldArchive != null && oldArchive.exists() &&
      !(oldArchive instanceof WritableArchive)) {
    outputFile.delete();
    out = archiveFactory.createArchive(outputFile);
    oldArchive.close();
  } else {
    out = archiveFactory.createArchive(new File(outPath));
  out.close();
  in.close();
      out.close();

代码示例来源:origin: org.glassfish.main.deployment/deployment-javaee-full

ReadableArchive subArchiveToExpand = null;
try {
  subArchive = source2.getSubArchive(moduleUri);
  if (subArchive == null) {
    _logger.log(Level.WARNING,
    moduleUri, subHandler);
  if (subHandler!=null) {
    subTarget = target.createSubArchive(
      FileUtils.makeFriendlyFilenameExtension(moduleUri));
        final String msg = MessageFormat.format(
            _logger.getResourceBundle().getString("enterprise.deployment.backend.badSubModPackaging"),
            subArchive.getURI().toASCIIString(),
            subArchive.getClass().getName());
        throw new RuntimeException(msg);
  try {
    if (subArchive != null) {
      subArchive.close();
      subTarget.close();

代码示例来源:origin: org.glassfish.main.deployment/dol

public void copyAnEntry(ReadableArchive in,
                WritableArchive out, String entryName) 
  throws IOException {
  InputStream is = null;
  InputStream is2 = null;
  ReadableArchive in2 = archiveFactory.openArchive(out.getURI());
  try {
    is = in.getEntry(entryName);
    is2 = in2.getEntry(entryName);
    if (is != null && is2 == null) {
      OutputStream os = out.putNextEntry(entryName);
      ArchivistUtils.copyWithoutClose(is, os);
    }
  } finally {
    /*
     *Close any streams that were opened.
     */
    in2.close();
    if (is != null) {
      is.close();
    }
    if (is2 != null) {
      is2.close();
    }
    out.closeEntry();
  }
}

代码示例来源:origin: org.glassfish.main.deployment/dol

/**
 * copy all contents of a jar file to a new jar file except
 * for all the deployment descriptors files
 *
 * @param in  jar file
 * @param out jar file
 * @param ignoreList vector of entry name to not copy from to source jar file
 */
protected void copyJarElements(ReadableArchive in, WritableArchive out, Vector ignoreList)
    throws IOException {
  Enumeration entries = in.entries();
  if (entries != null) {
    for (; entries.hasMoreElements();) {
      String anEntry = (String) entries.nextElement();
      if (ignoreList == null || !ignoreList.contains(anEntry)) {
        InputStream is = in.getEntry(anEntry);
        if (is != null) {
         OutputStream os = out.putNextEntry(anEntry);
         ArchivistUtils.copyWithoutClose(is, os);
         is.close();
        }
        out.closeEntry();
      }
    }
  }
}

代码示例来源:origin: org.glassfish.main.deployment/dol

DOLUtils.getDefaultLogger().fine("Write " + out.getURI() + " with " + this);
for (Enumeration alreadyWritten = out.entries(); alreadyWritten.hasMoreElements();) {
  String elementName = (String) alreadyWritten.nextElement();
  filesToSkip.add(elementName);
  WritableArchive internalJar = out.createSubArchive(aModule.getArchiveUri());
  try (InputStream is = in.getEntry(aModule.getArchiveUri())){
    if (in instanceof WritableArchive) {
      subArchivist.setArchiveUri(internalJar.getURI().getSchemeSpecificPart());
    } else {
      tmpFile = getTempFile(path);
    out.closeEntry(internalJar);
  } finally {
    if (tmpFile!=null) {

代码示例来源:origin: org.glassfish.deployment/dol

/**
 * writes the content of an archive to a JarFile
 *
 * @param in input  archive
 * @param out archive output stream to write to
 * @param entriesToSkip files to not write from the original archive
 */
protected void writeContents(ReadableArchive in, WritableArchive out, Vector entriesToSkip)
    throws IOException {
  // Copy original jarFile elements
  if (in != null && in.exists()) {
    if (entriesToSkip == null) {
      entriesToSkip = getListOfFilesToSkip();
    } else {
      entriesToSkip.addAll(getListOfFilesToSkip());
    }
    copyJarElements(in, out, entriesToSkip);
  }
  // now the deployment descriptors
  writeDeploymentDescriptors(out);
  // manifest file
  if (manifest != null) {
    OutputStream os = out.putNextEntry(JarFile.MANIFEST_NAME);
    manifest.write(new DataOutputStream(os));
    out.closeEntry();
  }
}

代码示例来源:origin: org.glassfish.deployment/dol

public void saveRuntimeInfo(File output) throws IOException {
  // if output file is null, we overwrite the current archive...
  File outputFile = output;
  if (outputFile == null) {
    outputFile = getTempFile(path);
  }
  // copy all entries from source to target except the 
  // runtime descriptor file
  WritableArchive out = archiveFactory.createArchive(outputFile);
  ReadableArchive in = archiveFactory.openArchive(new File(path));
  Vector skipFiles = new Vector();
  skipFiles.add(getRuntimeDeploymentDescriptorPath());
  copyInto(in, out, skipFiles);
  in.close();
  // now save the runtime deployment descriptor...
  OutputStream os = out.putNextEntry(getRuntimeDeploymentDescriptorPath());
  writeRuntimeDeploymentDescriptors(os);
  out.closeEntry();
  out.close();
  // if we overwrote the old archive, need to rename the tmp now
  if (output == null) {
    ReadableArchive finalArchive = archiveFactory.openArchive(new File(path));
    finalArchive.delete();
    ReadableArchive tmpArchive = archiveFactory.openArchive(outputFile);
    tmpArchive.renameTo(path);
  }
}

代码示例来源:origin: org.glassfish/osgi-javaee-base

throw new IOException("Not able to expand " + archive.getName() +
      " in " + tmpFile);
  new OSGiArchiveHandler().expand(archive, targetArchive, dc);
  logger.logp(Level.INFO, "OSGiDeploymentRequest", "expand",
      "Expanded at {0}", new Object[]{targetArchive.getURI()});
  archive = archiveFactory.openArchive(tmpFile);
} else {
  throw new IOException("Not able to expand " + archive.getName() +
      " in " + tmpFile);

代码示例来源:origin: org.glassfish.deployment/dol

if (!bundle.isFullFlag()) {
  if (ddFile != null) {
    OutputStream os = out.putNextEntry(ddPath);
    ddFile.write(bundle, os);
    out.closeEntry();
    if (webBundle.hasWebServices()) {
      if (ddFile != null) {
        OutputStream os = out.putNextEntry(ddPath);
        ddFile.write(webBundle, os);
        out.closeEntry();
DeploymentDescriptorFile confDDFile = moduleArchivist.getConfigurationDDFile();
if (confDDFile!=null) {
  OutputStream os = out.putNextEntry(runtimeDDPath);
  confDDFile.write(aModule.getDescriptor(), os);
  out.closeEntry();
WritableArchive moduleArchive = out.createSubArchive(aModule.getArchiveUri());
ReadableArchive moduleArchive2 = in.getSubArchive(aModule.getArchiveUri());
write((BundleDescriptor)aModule.getDescriptor(),  moduleArchivist, moduleArchive2, moduleArchive);

代码示例来源:origin: org.glassfish.main.deployment/dol

/**
 * writes an application deployment descriptors
 * @param the application object
 * @param the abstract archive
 */
public void write(Application application, ReadableArchive in,
  WritableArchive out) throws IOException {
  if (application.isVirtual()) {
    ModuleDescriptor aModule = (ModuleDescriptor) application.getModules().iterator().next();
    Archivist moduleArchivist = archivistFactory.getArchivist(aModule.getModuleType());
    write((BundleDescriptor)aModule.getDescriptor(), moduleArchivist, in, out);
  } else {
    // this is a real application.
    // let's start by writing out all submodules deployment descriptors
    for (ModuleDescriptor aModule : application.getModules()) {
      Archivist moduleArchivist = archivistFactory.getArchivist(aModule.getModuleType());
      WritableArchive moduleArchive = out.createSubArchive(aModule.getArchiveUri());
      ReadableArchive moduleArchive2 = in.getSubArchive(aModule.getArchiveUri());
      write((BundleDescriptor)aModule.getDescriptor(),  moduleArchivist, moduleArchive2, moduleArchive);
    }
    
    // now let's write the application descriptor
    ApplicationArchivist archivist = archivistProvider.get();
    archivist.setDescriptor(application);
    archivist.writeDeploymentDescriptors(in, out); 
  }
}

代码示例来源:origin: org.glassfish.main.core/kernel

Collection<String> directoryEntries = source.getDirectories();
List<String> subModuleEntries = new ArrayList<String>();
List<String> entriesToExclude = new ArrayList<String>();
      new FileInputStream(moduleJar));
    try {
      os = target.putNextEntry(moduleJar.getName());
      FileUtils.copy(is, os, moduleJar.length());
    } finally {
      if (os!=null) {
        target.closeEntry();
      OutputStream os = null;
      try {
        os = target.putNextEntry(entryName);
        FileUtils.copy(is, os, source.getEntrySize(entryName));
      } finally {
        if (os!=null) {
          target.closeEntry();
if (m!=null) {
  processManifest(m, appName);
  OutputStream os  = target.putNextEntry(JarFile.MANIFEST_NAME);
  m.write(os);
  target.closeEntry();
source.close();
target.close();

代码示例来源:origin: org.glassfish.main.deployment/dol

try {
  File outputFile=null;
  if (oldArchive != null && oldArchive.exists() &&
      !(oldArchive instanceof WritableArchive)) {
    outputFile.delete();
    out = archiveFactory.createArchive(outputFile);
    oldArchive.close();
  } else {
    out = archiveFactory.createArchive(new File(outPath));
  out.close();
  in.close();
      out.close();

相关文章