protected IFile saveFile(File aFile, IProject p) throws IOException { IFile iFile = p.getFile(aFile.getURI()); WorkbenchByteArrayOutputStream out = new WorkbenchByteArrayOutputStream(iFile); ArchiveUtil.copy(aFile.getInputStream(), out); return iFile; }
private byte[] getData(File file) { if (null != file) { try { return ArchiveUtil.inputStreamToBytes(file.getInputStream()); } catch (FileNotFoundException e) { return null; } catch (IOException e) { throw new ArchiveRuntimeException(CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.io_ex_loading_EXC_, (new Object[]{file.getName()})), e); // = "An IO exception occurred loading " } } } return null; }
/** * @see com.ibm.etools.common.command.Command */ public void execute() { List files = archive.getFiles(); for (int i = 0; i < files.size(); i++) { File aFile = (File) files.get(i); if (aFile.isArchive()) { new RepairArchiveCommand((Archive) aFile).execute(); } else { String upperUri = aFile.getURI().toUpperCase(); Iterator keysAndValues = directoryNames.entrySet().iterator(); while (keysAndValues.hasNext()) { String uri = aFile.getURI(); Map.Entry entry = (Map.Entry) keysAndValues.next(); String key = (String) entry.getKey(); String value = (String) entry.getValue(); if (upperUri.startsWith(key) && !uri.startsWith(value)) { String tail = uri.substring(key.length()); aFile.setURI(value.concat(tail)); break; } } } } }
public java.util.List filterFiles(String prefix, String[] suffixes) { List subset = new ArrayList(); List theFiles = getFiles(); for (int i = 0; i < theFiles.size(); i++) { File aFile = (File) theFiles.get(i); if (!aFile.isDirectoryEntry() && aFile.getURI().startsWith(prefix)) if (suffixes == null || hasSuffix(aFile.getURI(), suffixes)) subset.add(aFile); } return subset; }
/** * @see com.ibm.etools.commonarchive.WARFile */ public File addCopyLib(File aFile) throws DuplicateObjectException { if (aFile.isReadOnlyDirectory()) throw new IllegalArgumentException(CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.add_copy_lib_dir_EXC_, (new Object[]{aFile.getURI()}))); // = "Method addCopyLib not supported for directories :" return addCopyFileAddingPrefix(aFile, ArchiveConstants.WEBAPP_LIB_URI); }
protected void addFile(java.io.File aFile, List aList) { String uri = getURIFrom(aFile); if (collectedLooseArchiveFiles.containsKey(uri)) return; org.eclipse.jst.j2ee.commonarchivecore.internal.File cFile = createFile(uri); cFile.setSize(aFile.length()); cFile.setLastModified(aFile.lastModified()); aList.add(cFile); }
public void save(File aFile, InputStream in) throws SaveFailureException { try { progressMonitor.subTask(aFile.getURI()); IPath projectRelativePath = getOutputPathForFile(aFile); if (aFile.isArchive()) { saveAsArchiveComponent((Archive) aFile, projectRelativePath, in); } else if (!aFile.isDirectoryEntry()) { saveToOutputPath(projectRelativePath, in); } else { createDirectory(projectRelativePath); } } catch (OverwriteHandlerException ohe) { throw ohe; } catch (Exception e) { String errorString = EJBArchiveOpsResourceHandler.ARCHIVE_OPERATION_SaveFile + aFile.getName(); throw new SaveFailureException(errorString, e); } finally { progressMonitor.worked(1); } }
protected String getImportedClassesURI(File aFile) { return aFile.getURI(); }
protected void checkType(Module moduleDescriptor, File aFile) { if (aFile == null) { String message = CommonArchiveResourceHandler.getString(CommonArchiveResourceHandler.A_file_does_not_exist_for_module, new Object[]{moduleDescriptor.getUri()}); throw new NoModuleFileException(message); } //Added for defect 113929 boolean isValid = true; String type = CommonArchiveResourceHandler.Module_file; if (moduleDescriptor.isWebModule() && !aFile.isWARFile()) { isValid = false; type = CommonArchiveResourceHandler.A_WAR_file; } else if (moduleDescriptor.isEjbModule() && !aFile.isEJBJarFile()) { isValid = false; type = CommonArchiveResourceHandler.An_EJB_JAR_file; } else if (moduleDescriptor.isJavaModule() && !aFile.isApplicationClientFile()) { isValid = false; type = CommonArchiveResourceHandler.An_Application_Client_JAR_file; } else if (moduleDescriptor.isConnectorModule() && !aFile.isRARFile()) { isValid = false; type = CommonArchiveResourceHandler.A_RAR_file; } else if (!aFile.isModuleFile()) isValid = false; if (isValid) return; String earUri = ""; //$NON-NLS-1$ if (getEarFile() != null) earUri = getEarFile().getURI(); String message = CommonArchiveResourceHandler.getString("File_not_correct_type", new Object[]{aFile.getURI(), earUri, type}); //$NON-NLS-1$ throw new ArchiveRuntimeException(message); }
/** * @see com.ibm.etools.archive.SaveStrategy */ public void save(File aFile, FileIterator iterator) throws SaveFailureException { if (aFile.isArchive() && shouldIterateOver((Archive) aFile)) save((Archive) aFile); else { InputStream in = null; if (!aFile.isDirectoryEntry()) { try { in = iterator.getInputStream(aFile); } catch (IOException ex) { throw new SaveFailureException(aFile.getURI(), ex); } } save(aFile, in); } }
for (int i = 0; i < fileList.size(); i++) { File f = (File) fileList.get(i); f.setOriginalURI(f.getURI()); f.setLoadingContainer(this); if (f.isArchive()) ((Archive) f).reopen(this);
public void save(File aFile, InputStream in) throws SaveFailureException { try { String entryName = aFile.getURI(); if (aFile.isDirectoryEntry() && !entryName.endsWith("/"))//$NON-NLS-1$ entryName = entryName + '/'; ZipEntry entry = new ZipEntry(entryName); if (aFile.getLastModified() > 0) entry.setTime(aFile.getLastModified()); getZipOutputStream().putNextEntry(entry); if (!aFile.isDirectoryEntry()) { org.eclipse.jst.j2ee.commonarchivecore.internal.util.ArchiveUtil.copy(in, getZipOutputStream()); } getZipOutputStream().closeEntry(); } catch (IOException iox) { throw new SaveFailureException(aFile.getURI(), iox); } }
if (manifestToCopy != null) { File copiedManifest = (File) getCopy(manifestToCopy); copiedManifest.setLoadingContainer(manifestToCopy.getLoadingContainer()); copy.addCopy(copiedManifest); File aFile = (File) files.get(i); File copiedFile = (File) getCopy(aFile); copiedFile.setLoadingContainer(aFile.getLoadingContainer()); if (aFile.isArchive()) finishNestedCopy((Archive) aFile, (Archive) copiedFile);
/** * @see com.ibm.etools.archive.impl.LoadStrategyImpl */ public java.util.List getFiles() { List list = new ArrayList(); Enumeration entries = getZipFile().entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); if (!entry.isDirectory()){ if(!collectedLooseArchiveFiles.containsKey(entry.getName())) { File aFile = createFile(entry.getName()); aFile.setSize(entry.getSize()); aFile.setLastModified(entry.getTime()); list.add(aFile); } } else if(includeEmptyDirectories) { File aFile = createDirectory(entry.getName()); aFile.setDirectoryEntry(true); aFile.setSize(entry.getSize()); aFile.setLastModified(entry.getTime()); list.add(aFile); } } return list; }
/** * @see com.ibm.etools.commonarchive.EARFile */ public java.util.List getArchiveFiles() { List archives = new ArrayList(); List fileList = getFiles(); for (int i = 0; i < fileList.size(); i++) { File aFile = (File) fileList.get(i); if (aFile.isArchive()) { archives.add(aFile); } } return archives; }
public static Archive getClientJAR(EJBJarFile file, EARFile earFile) { EJBJar jar = null; try { jar = file.getDeploymentDescriptor(); } catch (DeploymentDescriptorLoadException exc) { return null; } if (jar == null) return null; String clientJAR = jar.getEjbClientJar(); if (clientJAR == null || clientJAR.length() == 0) return null; String normalized = ArchiveUtil.deriveEARRelativeURI(clientJAR, file.getURI()); if (normalized != null) { try { File aFile = earFile.getFile(normalized); if (aFile.isArchive() && !aFile.isModuleFile()) return (Archive) aFile; } catch (FileNotFoundException nothingThere) { } } return null; // TODO - release the DD here to free up space }
/** * @see com.ibm.etools.commonarchive.File */ public java.io.InputStream getInputStream() throws java.io.FileNotFoundException, java.io.IOException { if (getLoadingContainer() != null || getLoadStrategy() == null || getLoadStrategy().isDirectory()) return super.getInputStream(); //This archive was copied in; this operation is not supported for // module files if (isModuleFile() || !getOptions().isSaveLibrariesAsFiles()) throw new IOException("Undefined state of nested archive"); //$NON-NLS-1$ //We have to find the absolute path of the original archive from which // this was copied, //if it is known List list = getFiles(); String absolutePath = null; for (int i = 0; i < list.size(); i++) { File aFile = (File) list.get(i); if (aFile.isArchive()) continue; absolutePath = aFile.getLoadingContainer().getAbsolutePath(); } return new FileInputStream(absolutePath); }
protected File addCopyFileAddingPrefix(File aFile, String uriPrefix) throws DuplicateObjectException { String swizzledUri = aFile.getURI(); if (!swizzledUri.startsWith(uriPrefix)) { swizzledUri = ArchiveUtil.concatUri(uriPrefix, swizzledUri, '/'); } checkAddValid(swizzledUri); File copy = copy(aFile); copy.setURI(swizzledUri); getFiles().add(copy); return copy; }
protected void setTimestampAfterSaving(org.eclipse.jst.j2ee.commonarchivecore.internal.File aFile) { long lastMod = aFile.getLastModified(); if (lastMod == 0) return; String absPath = ArchiveUtil.getOSUri(getDirectoryName(), aFile.getURI()); File ioFile = new File(absPath); ioFile.setLastModified(lastMod); }