List of usage examples for java.util Collections list
public static <T> ArrayList<T> list(Enumeration<T> e)
From source file:org.eclipse.jdt.ls.core.internal.codemanipulation.ImportOrganizeTest.java
private void addFilesFromJar(IJavaProject javaProject, File jarFile, String encoding) throws InvocationTargetException, CoreException, IOException { IFolder src = (IFolder) fSourceFolder.getResource(); File targetFile = src.getLocation().toFile(); try (JarFile file = new JarFile(jarFile)) { for (JarEntry entry : Collections.list(file.entries())) { if (entry.isDirectory()) { continue; }/* w w w . ja v a 2 s . com*/ try (InputStream in = file.getInputStream(entry); Reader reader = new InputStreamReader(in, encoding)) { File outFile = new File(targetFile, entry.getName()); outFile.getParentFile().mkdirs(); try (OutputStream out = new FileOutputStream(outFile); Writer writer = new OutputStreamWriter(out, encoding)) { IOUtils.copy(reader, writer); } } } } javaProject.getProject().refreshLocal(IResource.DEPTH_INFINITE, new NullProgressMonitor()); }
From source file:org.paxle.data.impl.Activator.java
@SuppressWarnings("unchecked") private void createAndRegisterCommandDB(URL hibernateConfigFile, BundleContext context) throws InvalidSyntaxException { // getting the Event-Admin service ServiceReference commandTrackerRef = context.getServiceReference(ICommandTracker.class.getName()); ICommandTracker commandTracker = (commandTrackerRef == null) ? null : (ICommandTracker) context.getService(commandTrackerRef); if (commandTracker == null) throw new IllegalStateException("No CommandTracker-service found. Command-tracking will not work."); // getting the doc-factory ServiceReference[] cmdFactoryRefs = context.getServiceReferences(IDocumentFactory.class.getName(), String.format("(%s=%s)", IDocumentFactory.DOCUMENT_TYPE, ICommand.class.getName())); if (cmdFactoryRefs == null || cmdFactoryRefs.length == 0) throw new IllegalStateException("No DocFactory found."); final IDocumentFactory cmdFactory = (IDocumentFactory) context.getService(cmdFactoryRefs[0]); // getting the mapping files to use Enumeration<URL> mappingFileEnum = context.getBundle().findEntries("/resources/hibernate/mapping/command/", "command.hbm.xml", true); ArrayList<URL> mappings = Collections.list(mappingFileEnum); // init command DB this.commandDB = new CommandDB(hibernateConfigFile, mappings, commandTracker, cmdFactory); final Hashtable<String, Object> props = new Hashtable<String, Object>(); props.put(IDataSink.PROP_DATASINK_ID, ICommandDB.PROP_URL_ENQUEUE_SINK); props.put(IDataProvider.PROP_DATAPROVIDER_ID, "org.paxle.crawler.sink"); props.put(EventConstants.EVENT_TOPIC, new String[] { CommandEvent.TOPIC_OID_REQUIRED }); props.put(Constants.SERVICE_PID, CommandDB.PID); props.put("Monitorable-Localization", "/OSGI-INF/l10n/CommandDB"); context.registerService(new String[] { IDataSink.class.getName(), IDataProvider.class.getName(), ICommandDB.class.getName(), EventHandler.class.getName(), Monitorable.class.getName() }, this.commandDB, props); }
From source file:com.facebook.buck.util.unarchive.Unzip.java
/** * Get a listing of all files in a zip file that start with a prefix, ignore others * * @param zip The zip file to scan//from w ww. j av a 2 s . co m * @param relativePath The relative path where the extraction will be rooted * @param prefix The prefix that will be stripped off. * @return The list of paths in {@code zip} sorted by path so dirs come before contents. Prefixes * are stripped from paths in the zip file, such that foo/bar/baz.txt with a prefix of foo/ * will be in the map at {@code relativePath}/bar/baz.txt */ private static SortedMap<Path, ZipArchiveEntry> getZipFilePathsStrippingPrefix(ZipFile zip, Path relativePath, Path prefix, PatternsMatcher entriesToExclude) { SortedMap<Path, ZipArchiveEntry> pathMap = new TreeMap<>(); for (ZipArchiveEntry entry : Collections.list(zip.getEntries())) { String entryName = entry.getName(); if (entriesToExclude.matchesAny(entryName)) { continue; } Path entryPath = Paths.get(entryName); if (entryPath.startsWith(prefix)) { Path target = relativePath.resolve(prefix.relativize(entryPath)).normalize(); pathMap.put(target, entry); } } return pathMap; }
From source file:org.sakaiproject.nakamura.importer.ImportSiteArchiveServlet.java
/** * {@inheritDoc}/*from www.j av a 2 s. c o m*/ * * @see org.apache.sling.api.servlets.SlingAllMethodsServlet#doPost(org.apache.sling.api.SlingHttpServletRequest, * org.apache.sling.api.SlingHttpServletResponse) */ @Override protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException { final RequestParameter siteParam = request.getRequestParameter("site"); if (siteParam == null || !siteParam.getString().startsWith("/")) { final String errorMessage = "A site must be specified, and it must be an absolute path pointing to a site."; sendError(HttpServletResponse.SC_BAD_REQUEST, errorMessage, new IllegalArgumentException(errorMessage), response); return; } final String sitePath = siteParam.getString(); final RequestParameter[] files = request.getRequestParameters("Filedata"); if (files == null || files.length < 1) { final String errorMessage = "Missing Filedata parameter."; sendError(HttpServletResponse.SC_BAD_REQUEST, errorMessage, new IllegalArgumentException(errorMessage), response); return; } final Session session = request.getResourceResolver().adaptTo(Session.class); for (RequestParameter p : files) { LOG.info("Processing file: " + p.getFileName() + ": " + p.getContentType() + ": " + p.getSize() + " bytes"); try { // create temporary local file of zip contents final File tempZip = File.createTempFile("siteArchive", ".zip"); tempZip.deleteOnExit(); // just in case final InputStream in = p.getInputStream(); final FileOutputStream out = new FileOutputStream(tempZip); final byte[] buf = new byte[4096]; int len; while ((len = in.read(buf)) > 0) { out.write(buf, 0, len); } in.close(); out.close(); // process the zip file ZipFile zip = null; try { zip = new ZipFile(tempZip); } catch (ZipException e) { sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, "Invalid zip file: " + p.getFileName() + ": " + p.getContentType() + ": " + p.getSize(), null, response); } if (zip != null) { for (ZipEntry entry : Collections.list(zip.entries())) { if (entry.getName().startsWith("__MACOSX") || entry.getName().endsWith(".DS_Store")) { ; // skip entry } else { if ("content.xml".equals(entry.getName())) { processContentXml(zip.getInputStream(entry), sitePath, session, zip); } } } zip.close(); } // delete temporary file if (tempZip.delete()) { LOG.debug("{}: temporary zip file deleted.", tempZip.getAbsolutePath()); } else { LOG.warn("Could not delete temporary file: {}", tempZip.getAbsolutePath()); } } catch (IOException e) { sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getLocalizedMessage(), e, response); } catch (XMLStreamException e) { sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getLocalizedMessage(), e, response); } } response.setStatus(HttpServletResponse.SC_OK); return; }
From source file:com.eucalyptus.simpleworkflow.common.client.WorkflowClientStandalone.java
private void processJar(File f) throws Exception { final JarFile jar = new JarFile(f); final Properties props = new Properties(); final List<JarEntry> jarList = Collections.list(jar.entries()); LOG.trace("-> Trying to load component info from " + f.getAbsolutePath()); for (final JarEntry j : jarList) { try {/*from w w w . j ava 2s . co m*/ if (j.getName().matches(".*\\.class.{0,1}")) { handleClassFile(f, j); } } catch (RuntimeException ex) { LOG.error(ex, ex); jar.close(); throw ex; } } jar.close(); }
From source file:org.apache.qpid.server.management.plugin.HttpManagementUtil.java
public static OutputStream getOutputStream(final HttpServletRequest request, final HttpServletResponse response, HttpManagementConfiguration managementConfiguration) throws IOException { OutputStream outputStream;/*from ww w .j ava 2 s . c om*/ if (managementConfiguration.isCompressResponses() && Collections.list(request.getHeaderNames()).contains(ACCEPT_ENCODING_HEADER) && request.getHeader(ACCEPT_ENCODING_HEADER).contains(GZIP_CONTENT_ENCODING)) { outputStream = new GZIPOutputStream(response.getOutputStream()); response.setHeader(CONTENT_ENCODING_HEADER, GZIP_CONTENT_ENCODING); } else { outputStream = response.getOutputStream(); } return outputStream; }
From source file:com.twinsoft.convertigo.beans.core.MySimpleBeanInfo.java
protected PropertyDescriptor getPropertyDescriptor(String name) throws IntrospectionException { checkAdditionalProperties();// w w w . j ava2 s .c om for (int i = 0; i < properties.length; i++) { PropertyDescriptor property = properties[i]; if (name.equals(property.getName())) { PropertyDescriptor clone = new PropertyDescriptor(name, property.getReadMethod(), property.getWriteMethod()); clone.setDisplayName(property.getDisplayName()); clone.setShortDescription(property.getShortDescription()); clone.setPropertyEditorClass(property.getPropertyEditorClass()); clone.setBound(property.isBound()); clone.setConstrained(property.isConstrained()); clone.setExpert(property.isExpert()); clone.setHidden(property.isHidden()); clone.setPreferred(property.isPreferred()); for (String attributeName : Collections.list(property.attributeNames())) { clone.setValue(attributeName, property.getValue(attributeName)); } return properties[i] = clone; } } return null; }
From source file:com.fujitsu.dc.engine.rs.AbstractService.java
/** * Service./*from ww w . j a va 2 s . c o m*/ * @param cell Cell?? * @param scheme URI * @param svcName ??? * @param req Request * @param res Response * @param is * @return Response */ public final Response run(final String cell, final String scheme, final String svcName, final HttpServletRequest req, final HttpServletResponse res, final InputStream is) { StringBuilder msg = new StringBuilder(); msg.append("[" + DcEngineConfig.getVersion() + "] " + ">>> Request Started "); msg.append(" method:"); msg.append(req.getMethod()); msg.append(" method:"); msg.append(req.getRequestURL()); msg.append(" url:"); msg.append(cell); msg.append(" scheme:"); msg.append(scheme); msg.append(" svcName:"); msg.append(svcName); log.info(msg); // ? ???? Enumeration<String> multiheaders = req.getHeaderNames(); for (String headerName : Collections.list(multiheaders)) { Enumeration<String> headers = req.getHeaders(headerName); for (String header : Collections.list(headers)) { log.debug("RequestHeader['" + headerName + "'] = " + header); } } this.setServiceName(svcName); // ?URL?? String targetCell = cell; if (cell == null) { targetCell = getCell(); } String targetScheme = scheme; if (scheme == null) { targetScheme = getScheme(); } String targetServiceName = svcName; String baseUrl; try { baseUrl = parseRequestUri(req, res); } catch (MalformedURLException e) { // URL??????? return makeErrorResponse("Server Error", DcEngineException.STATUSCODE_SERVER_ERROR); } Response response = null; DcEngineContext dcContext = null; try { try { dcContext = new DcEngineContext(); } catch (DcEngineException e) { return errorResponse(e); } // ??? try { this.sourceManager = this.getServiceCollectionManager(); dcContext.setSourceManager(this.sourceManager); this.serviceSubject = this.sourceManager.getServiceSubject(); } catch (DcEngineException e) { return errorResponse(e); } // ?? dcContext.loadGlobalObject(baseUrl, targetCell, targetScheme, targetScheme, targetServiceName); // ??? String source = ""; try { String sourceName = this.sourceManager.getScriptNameForServicePath(targetServiceName); source = this.sourceManager.getSource(sourceName); } catch (DcEngineException e) { return errorResponse(e); } catch (Exception e) { log.info("User Script not found to targetCell(" + targetCell + ", targetScheme(" + targetScheme + "), targetServiceName(" + targetServiceName + ")"); log.info(e.getMessage(), e); return errorResponse(new DcEngineException("404 Not Found (User Script)", DcEngineException.STATUSCODE_NOTFOUND)); } // JSGI try { response = dcContext.runJsgi(source, req, res, is, this.serviceSubject); } catch (DcEngineException e) { return errorResponse(e); } catch (Exception e) { log.warn(" unknown Exception(" + e.getMessage() + ")"); return errorResponse(new DcEngineException("404 Not Found (Service Excute Error)", DcEngineException.STATUSCODE_NOTFOUND)); } } finally { IOUtils.closeQuietly(dcContext); } return response; }
From source file:org.rhq.enterprise.server.plugin.pc.perspective.PerspectiveServerPluginManager.java
private void undeployWars(ServerPluginEnvironment env) { String name = null;// w w w .j a v a2s . c o m try { JarFile plugin = new JarFile(env.getPluginUrl().getFile()); try { for (JarEntry entry : Collections.list(plugin.entries())) { name = entry.getName(); if (name.toLowerCase().endsWith(".war")) { undeployWar(getDeployFile(env, entry.getName())); } } } finally { plugin.close(); } } catch (Exception e) { this.log.error("Failed to deploy " + env.getPluginKey().getPluginName() + "#" + name, e); } }
From source file:sk.baka.aedict.indexer.TanakaParser.java
public void addLine(String line, IndexWriter writer) throws IOException { if (line.startsWith("A: ")) { doc = new Document(); lastLine = line.substring(3);//from ww w. j a v a 2 s . c o m lastLine = lastLine.substring(0, lastLine.indexOf('\t')); final ArrayList<Object> parsed = Collections.list(new StringTokenizer(line.substring(3), "\t#")); final String japanese = (String) parsed.get(0); final String english = (String) parsed.get(1); doc.add(new Field("japanese", japanese, Field.Store.YES, Field.Index.ANALYZED)); doc.add(new Field("english", english, Field.Store.YES, Field.Index.ANALYZED)); return; } if (!line.startsWith("B: ")) { throw new IllegalArgumentException("The TanakaCorpus file has unexpected format: line " + line); } final BLineParser parser = new BLineParser(edict, lastLine, line.substring(3)); doc.add(new Field("jp-deinflected", parser.dictionaryFormWordList, Field.Store.YES, Field.Index.ANALYZED)); doc.add(new Field("kana", CompressionTools.compressString(parser.kana), Field.Store.YES)); writer.addDocument(doc); }