List of usage examples for java.util Collections list
public static <T> ArrayList<T> list(Enumeration<T> e)
From source file:com.gisgraphy.webapp.filter.LocaleRequestWrapper.java
/** * {@inheritDoc}// ww w .j a v a 2 s . c om */ @Override @SuppressWarnings("unchecked") public Enumeration<Locale> getLocales() { if (null != preferredLocale) { List<Locale> l = Collections.list(super.getLocales()); if (l.contains(preferredLocale)) { l.remove(preferredLocale); } l.add(0, preferredLocale); return Collections.enumeration(l); } else { return super.getLocales(); } }
From source file:org.commonjava.maven.galley.filearc.internal.ZipListing.java
@Override public ListingResult call() { final File src = getArchiveFile(resource.getLocationUri()); if (!src.canRead() || src.isDirectory()) { return null; }//from w w w . java2s . c o m final boolean isJar = isJar(resource.getLocationUri()); final TreeSet<String> filenames = new TreeSet<String>(); ZipFile zf = null; try { if (isJar) { zf = new JarFile(src); } else { zf = new ZipFile(src); } final String path = resource.getPath(); final int pathLen = path.length(); for (final ZipEntry entry : Collections.list(zf.entries())) { String name = entry.getName(); if (name.startsWith(path)) { name = name.substring(pathLen); if (name.startsWith("/") && name.length() > 1) { name = name.substring(1); if (name.indexOf("/") < 0) { filenames.add(name); } } } } } catch (final IOException e) { error = new TransferException("Failed to get listing for: %s to: %s. Reason: %s", e, resource, e.getMessage()); } finally { if (zf != null) { try { zf.close(); } catch (final IOException e) { } } } if (!filenames.isEmpty()) { OutputStream stream = null; try { stream = target.openOutputStream(TransferOperation.DOWNLOAD); stream.write(join(filenames, "\n").getBytes("UTF-8")); return new ListingResult(resource, filenames.toArray(new String[filenames.size()])); } catch (final IOException e) { error = new TransferException("Failed to write listing to: %s. Reason: %s", e, target, e.getMessage()); } finally { closeQuietly(stream); } } return null; }
From source file:com.steeleforge.aem.ironsites.i18n.I18nResourceBundle.java
@Override public Enumeration<String> getKeys() { Set<String> names = new HashSet<String>(); if (null != parent) { names.addAll(Collections.list(parent.getKeys())); }//from w ww . j a v a 2 s . co m if (null != bundle) { names.addAll(Collections.list(bundle.getKeys())); } if (null != content && null != content.keySet()) { names.addAll(content.keySet()); } return Collections.enumeration(names); }
From source file:zipkin.server.brave.BraveConfiguration.java
/** This gets the lanIP without trying to lookup its name. */ // http://stackoverflow.com/questions/8765578/get-local-ip-address-without-connecting-to-the-internet @Bean//ww w.j a v a 2s .com @Scope Endpoint local(@Value("${server.port:9411}") int port) { Endpoint.Builder builder = Endpoint.builder().serviceName("zipkin-server").port(port == -1 ? 0 : port); try { byte[] address = Collections.list(NetworkInterface.getNetworkInterfaces()).stream() .flatMap(i -> Collections.list(i.getInetAddresses()).stream()) .filter(ip -> ip.isSiteLocalAddress()).findAny().get().getAddress(); if (address.length == 4) { builder.ipv4(ByteBuffer.wrap(address).getInt()); } else if (address.length == 16) { builder.ipv6(address); } } catch (Exception ignored) { builder.ipv4(127 << 24 | 1); } return builder.build(); }
From source file:net.minecraftforge.fml.common.discovery.JarDiscoverer.java
@Override public List<ModContainer> discover(ModCandidate candidate, ASMDataTable table) { List<ModContainer> foundMods = Lists.newArrayList(); FMLLog.fine("Examining file %s for potential mods", candidate.getModContainer().getName()); JarFile jar = null;/* w w w. j a v a 2s . c om*/ try { jar = new JarFile(candidate.getModContainer()); ZipEntry modInfo = jar.getEntry("mcmod.info"); MetadataCollection mc = null; if (modInfo != null) { FMLLog.finer("Located mcmod.info file in file %s", candidate.getModContainer().getName()); InputStream inputStream = jar.getInputStream(modInfo); try { mc = MetadataCollection.from(inputStream, candidate.getModContainer().getName()); } finally { IOUtils.closeQuietly(inputStream); } } else { FMLLog.fine("The mod container %s appears to be missing an mcmod.info file", candidate.getModContainer().getName()); mc = MetadataCollection.from(null, ""); } for (ZipEntry ze : Collections.list(jar.entries())) { if (ze.getName() != null && ze.getName().startsWith("__MACOSX")) { continue; } Matcher match = classFile.matcher(ze.getName()); if (match.matches()) { ASMModParser modParser; try { InputStream inputStream = jar.getInputStream(ze); try { modParser = new ASMModParser(inputStream); } finally { IOUtils.closeQuietly(inputStream); } candidate.addClassEntry(ze.getName()); } catch (LoaderException e) { FMLLog.log(Level.ERROR, e, "There was a problem reading the entry %s in the jar %s - probably a corrupt zip", ze.getName(), candidate.getModContainer().getPath()); jar.close(); throw e; } modParser.validate(); modParser.sendToTable(table, candidate); ModContainer container = ModContainerFactory.instance().build(modParser, candidate.getModContainer(), candidate); if (container != null) { table.addContainer(container); foundMods.add(container); container.bindMetadata(mc); container.setClassVersion(modParser.getClassVersion()); } } } } catch (Exception e) { FMLLog.log(Level.WARN, e, "Zip file %s failed to read properly, it will be ignored", candidate.getModContainer().getName()); } finally { Java6Utils.closeZipQuietly(jar); } return foundMods; }
From source file:alpha.portal.webapp.filter.LocaleRequestWrapper.java
/** * {@inheritDoc}// w w w .ja v a 2 s . c o m */ @Override @SuppressWarnings("unchecked") public Enumeration<Locale> getLocales() { if (null != this.preferredLocale) { final List<Locale> l = Collections.list(super.getLocales()); if (l.contains(this.preferredLocale)) { l.remove(this.preferredLocale); } l.add(0, this.preferredLocale); return Collections.enumeration(l); } else return super.getLocales(); }
From source file:org.apache.hadoop.hdfs.server.namenode.TestNameNodeMetricsLogger.java
@Test public void testMetricsLoggerIsAsync() throws IOException { makeNameNode(true);//from www . j a va 2 s .com org.apache.log4j.Logger logger = ((Log4JLogger) NameNode.MetricsLog).getLogger(); @SuppressWarnings("unchecked") List<Appender> appenders = Collections.list(logger.getAllAppenders()); assertTrue(appenders.get(0) instanceof AsyncAppender); }
From source file:be.fedict.eid.dss.model.bean.ServicesManagerBean.java
public List<String> getSupportedDocumentFormats() { Set<String> documentFormats = this.servicesManagerSingleton.getSupportedDocumentFormats(); return Collections.list(Collections.enumeration(documentFormats)); }
From source file:cc.arduino.net.PACSupportMethods.java
public String myIpAddress() throws SocketException { Optional<NetworkInterface> publicIface = Collections.list(NetworkInterface.getNetworkInterfaces()).stream() .filter((iface) -> {// w w w . j a va2s .c om try { return !iface.isLoopback(); } catch (SocketException e) { throw new RuntimeException(e); } }).filter((iface) -> iface.getInetAddresses().hasMoreElements()).findFirst(); if (publicIface.isPresent()) { return publicIface.get().getInetAddresses().nextElement().getHostAddress(); } return "127.0.0.1"; }
From source file:org.onehippo.repository.xml.ExportImportPackageTest.java
@Test public void testExportImportPackage() throws Exception { HippoSession session = (HippoSession) this.session; final File file = session.exportEnhancedSystemViewPackage("/test", true); ZipFile zipFile = new ZipFile(file); InputStream esvIn = null;//from ww w . j ava 2 s .c o m try { List<? extends ZipEntry> entries = Collections.list(zipFile.entries()); assertEquals(2, entries.size()); // esv.xml and one binary ZipEntry esvXmlEntry = null; ZipEntry binaryEntry = null; for (ZipEntry entry : entries) { if (entry.getName().equals("esv.xml")) { esvXmlEntry = entry; } else { binaryEntry = entry; } } assertNotNull(esvXmlEntry); assertNotNull(binaryEntry); InputStream binaryInput = zipFile.getInputStream(binaryEntry); assertEquals("test", IOUtils.toString(binaryInput)); binaryInput.close(); if (log.isDebugEnabled()) { log.debug("Created package at " + file.getPath()); } ContentResourceLoader contentResourceLoader = new ZipFileContentResourceLoader(zipFile); esvIn = contentResourceLoader.getResourceAsStream("esv.xml"); session.importEnhancedSystemViewXML("/test", esvIn, ImportUUIDBehavior.IMPORT_UUID_COLLISION_THROW, ImportReferenceBehavior.IMPORT_REFERENCE_NOT_FOUND_THROW, contentResourceLoader); assertTrue(session.nodeExists("/test/test")); final Node test = session.getNode("/test/test"); assertTrue(test.hasProperty("test")); binaryInput = test.getProperty("test").getBinary().getStream(); assertEquals("test", IOUtils.toString(binaryInput)); binaryInput.close(); } finally { IOUtils.closeQuietly(esvIn); zipFile.close(); if (!log.isDebugEnabled()) { FileUtils.deleteQuietly(file); } } }