List of usage examples for com.google.common.collect Iterators toArray
@GwtIncompatible("Array.newInstance(Class, int)") public static <T> T[] toArray(Iterator<? extends T> iterator, Class<T> type)
From source file:com.anhth12.lambda.common.text.TextUtils.java
private static String[] doParseDelimited(String delimited, CSVFormat format) { Iterator<CSVRecord> records; try {// w w w .ja va 2 s . com records = CSVParser.parse(delimited, format).iterator(); } catch (IOException ex) { throw new IllegalStateException(ex); } if (records.hasNext()) { return Iterators.toArray(records.next().iterator(), String.class); } else { return EMPTY_STRING; } }
From source file:io.wcm.config.core.management.impl.PersistenceTypeConversion.java
/** * Convert object to be persisted./* w ww. j av a 2 s . co m*/ * @param value Configured value * @param parameterType Parameter type * @return value that can be persisted */ public static Object toPersistenceType(Object value, Class<?> parameterType) { if (!isTypeConversionRequired(parameterType)) { return value; } if (Map.class.isAssignableFrom(parameterType) && (value instanceof Map)) { Map<?, ?> map = (Map<?, ?>) value; Map.Entry<?, ?>[] entries = Iterators.toArray(map.entrySet().iterator(), Map.Entry.class); String[] stringArray = new String[entries.length]; for (int i = 0; i < entries.length; i++) { Map.Entry<?, ?> entry = entries[i]; String entryKey = Objects.toString(entry.getKey(), ""); String entryValue = Objects.toString(entry.getValue(), ""); stringArray[i] = entryKey + KEY_VALUE_DELIMITER + entryValue; } return stringArray; } throw new IllegalArgumentException("Type conversion not supported: " + parameterType.getName()); }
From source file:com.kixeye.chassis.bootstrap.spring.ArchaiusSpringPropertySource.java
@Override public String[] getPropertyNames() { return Iterators.toArray(ConfigurationManager.getConfigInstance().getKeys(), String.class); }
From source file:com.kixeye.chassis.bootstrap.spring.ArgumentsPropertySource.java
@Override public String[] getPropertyNames() { return Iterators.toArray(source.asPropertyMap().keySet().iterator(), String.class); }
From source file:org.jasig.portal.utils.web.FileUploadLogger.java
public static void logFileUploadInfo(HttpServletRequest request) { final boolean multipartContent = ServletFileUpload.isMultipartContent(request); System.out.println("multipartContent=" + multipartContent); if (!multipartContent) { return;//w w w .j a va 2 s . c o m } DiskFileItemFactory factory = new DiskFileItemFactory(); final ServletFileUpload servletFileUpload = new ServletFileUpload(factory); try { final FileItemIterator itemIterator = servletFileUpload.getItemIterator(request); while (itemIterator.hasNext()) { final FileItemStream next = itemIterator.next(); System.out.println("FileItemStream: " + next.getName()); System.out.println("\t" + next.getContentType()); System.out.println("\t" + next.getFieldName()); final FileItemHeaders headers = next.getHeaders(); if (headers != null) { System.out.println( "\t" + Arrays.toString(Iterators.toArray(headers.getHeaderNames(), String.class))); } } } catch (Exception e) { e.printStackTrace(); } }
From source file:io.grpc.ServiceProvidersTestUtil.java
/** * Creates an iterator from the callable class via reflection, and checks that all expected * classes were loaded./*from w ww. j a va 2 s. c om*/ * * <p>{@code callableClassName} is a {@code Callable<Iterable<Class<?>>} rather than the iterable * class name itself so that the iterable class can be non-public. * * <p>We accept class names as input so that we can test against classes not in the * testing class path. */ static void testHardcodedClasses(String callableClassName, ClassLoader cl, Set<String> hardcodedClassNames) throws Exception { final Set<String> notLoaded = new HashSet<String>(hardcodedClassNames); cl = new ClassLoader(cl) { @Override public Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException { if (notLoaded.remove(name)) { throw new ClassNotFoundException(); } else { return super.loadClass(name, resolve); } } }; cl = new StaticTestingClassLoader(cl, Pattern.compile("io\\.grpc\\.[^.]*")); // Some classes fall back to the context class loader. // Ensure that the context class loader is not an accidental backdoor. ClassLoader ccl = Thread.currentThread().getContextClassLoader(); try { Thread.currentThread().setContextClassLoader(cl); Object[] results = Iterators.toArray(invokeIteratorCallable(callableClassName, cl), Object.class); assertWithMessage("The Iterable loaded a class that was not in hardcodedClassNames").that(results) .isEmpty(); assertWithMessage("The Iterable did not attempt to load some classes from hardcodedClassNames") .that(notLoaded).isEmpty(); } finally { Thread.currentThread().setContextClassLoader(ccl); } }
From source file:org.apache.hive.ptest.conf.QFileTestBatch.java
public QFileTestBatch(String driver, String queryFilesProperty, Set<String> tests, boolean isParallel) { this.driver = driver; this.queryFilesProperty = queryFilesProperty; this.tests = tests; String name = Joiner.on("-").join(driver, Joiner.on("-").join(Iterators.toArray(Iterators.limit(tests.iterator(), 3), String.class))); if (tests.size() > 3) { name = Joiner.on("-").join(name, "and", (tests.size() - 3), "more"); }/*from w ww .ja v a2s . c o m*/ this.name = name; this.isParallel = isParallel; }
From source file:org.sonar.batch.scan.LastLineHashes.java
public String[] getLineHashes(String fileKey) { String hashesFromWs = loadHashesFromWs(fileKey); return Iterators.toArray(Splitter.on('\n').split(hashesFromWs).iterator(), String.class); }
From source file:org.sonar.scanner.issue.tracking.DefaultServerLineHashesLoader.java
@Override public String[] getLineHashes(String fileKey) { String hashesFromWs = loadHashesFromWs(fileKey); return Iterators.toArray(Splitter.on('\n').split(hashesFromWs).iterator(), String.class); }
From source file:org.sonar.batch.issue.tracking.DefaultServerLineHashesLoader.java
@Override public String[] getLineHashes(String fileKey, @Nullable MutableBoolean fromCache) { String hashesFromWs = loadHashesFromWs(fileKey, fromCache); return Iterators.toArray(Splitter.on('\n').split(hashesFromWs).iterator(), String.class); }