List of usage examples for org.apache.commons.io IOUtils readLines
public static List readLines(InputStream input, String encoding) throws IOException
InputStream
as a list of Strings, one entry per line, using the specified character encoding. From source file:gnete.card.service.impl.MerchServiceImpl.java
/** * ?//from w w w.j a v a2 s.c o m * @param fileData * @return * @throws BizException */ private List getLines(byte[] fileData) throws BizException { // ?. List lines = null; try { lines = IOUtils.readLines(new ByteArrayInputStream(fileData), DEFAULT_ENCODING); } catch (IOException e) { logger.error(e, e); throw new BizException("?, ?"); } return lines; }
From source file:com.jivesoftware.os.upena.deployable.UpenaMain.java
private void injectUI(String upenaVersion, AWSClientFactory awsClientFactory, ObjectMapper storeMapper, ObjectMapper mapper, JDIAPI jvmapi, AmzaService amzaService, PathToRepo localPathToRepo, RepositoryProvider repositoryProvider, HostKey hostKey, UpenaRingHost ringHost, UpenaSSLConfig upenaSSLConfig, int port, SessionStore sessionStore, UbaService ubaService, UpenaHealth upenaHealth, UpenaStore upenaStore, UpenaConfigStore upenaConfigStore, UpenaJerseyEndpoints jerseyEndpoints, String humanReadableUpenaClusterName, DiscoveredRoutes discoveredRoutes) throws SoySyntaxException, IOException { SoyFileSet.Builder soyFileSetBuilder = new SoyFileSet.Builder(); LOG.info("Add...."); URL dirURL = UpenaMain.class.getClassLoader().getResource("resources/soy/"); if (dirURL != null && dirURL.getProtocol().equals("jar")) { String jarPath = dirURL.getPath().substring(5, dirURL.getPath().indexOf("!")); JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8")); Enumeration<JarEntry> entries = jar.entries(); while (entries.hasMoreElements()) { String name = entries.nextElement().getName(); if (name.endsWith(".soy") && name.startsWith("resources/soy/")) { String soyName = name.substring(name.lastIndexOf('/') + 1); LOG.info("/" + name + " " + soyName); soyFileSetBuilder.add(this.getClass().getResource("/" + name), soyName); }//from w ww . j a va2s. c o m } } else { List<String> soyFiles = IOUtils.readLines(this.getClass().getResourceAsStream("resources/soy/"), StandardCharsets.UTF_8); for (String soyFile : soyFiles) { LOG.info("Adding {}", soyFile); soyFileSetBuilder.add(this.getClass().getResource("/resources/soy/" + soyFile), soyFile); } } SoyFileSet sfs = soyFileSetBuilder.build(); SoyTofu tofu = sfs.compileToTofu(); SoyRenderer renderer = new SoyRenderer(tofu, new SoyDataUtils()); SoyService soyService = new SoyService(upenaVersion, renderer, //new HeaderRegion("soy.upena.chrome.headerRegion", renderer), new MenuRegion("soy.upena.chrome.menuRegion", renderer), new HomeRegion("soy.upena.page.homeRegion", renderer, hostKey, upenaStore, ubaService), humanReadableUpenaClusterName, hostKey, upenaStore); AuthPluginRegion authRegion = new AuthPluginRegion("soy.upena.page.authPluginRegion", renderer); OktaMFAAuthPluginRegion oktaMFAAuthRegion = new OktaMFAAuthPluginRegion( "soy.upena.page.oktaMFAAuthPluginRegion", renderer); jerseyEndpoints.addInjectable(OktaMFAAuthPluginRegion.class, oktaMFAAuthRegion); UnauthorizedPluginRegion unauthorizedRegion = new UnauthorizedPluginRegion( "soy.upena.page.unauthorizedPluginRegion", renderer); PluginHandle auth = new PluginHandle("login", null, "Login", "/ui/auth/login", AuthPluginEndpoints.class, authRegion, null, "read"); HealthPluginRegion healthPluginRegion = new HealthPluginRegion(mapper, System.currentTimeMillis(), ringHost, "soy.upena.page.healthPluginRegion", "soy.upena.page.instanceHealthPluginRegion", "soy.upena.page.healthPopup", renderer, upenaHealth, upenaStore); ReleasesPluginRegion releasesPluginRegion = new ReleasesPluginRegion(mapper, repositoryProvider, "soy.upena.page.releasesPluginRegion", "soy.upena.page.releasesPluginRegionList", renderer, upenaStore); HostsPluginRegion hostsPluginRegion = new HostsPluginRegion("soy.upena.page.hostsPluginRegion", "soy.upena.page.removeHostPluginRegion", renderer, upenaStore); InstancesPluginRegion instancesPluginRegion = new InstancesPluginRegion( "soy.upena.page.instancesPluginRegion", "soy.upena.page.instancesPluginRegionList", renderer, upenaHealth, upenaStore, hostKey, healthPluginRegion, awsClientFactory); PluginHandle health = new PluginHandle("fire", null, "Health", "/ui/health", HealthPluginEndpoints.class, healthPluginRegion, null, "read"); PluginHandle topology = new PluginHandle("th", null, "Topology", "/ui/topology", TopologyPluginEndpoints.class, new TopologyPluginRegion(mapper, "soy.upena.page.topologyPluginRegion", "soy.upena.page.connectionsHealth", renderer, upenaHealth, amzaService, upenaSSLConfig, upenaStore, healthPluginRegion, hostsPluginRegion, releasesPluginRegion, instancesPluginRegion, discoveredRoutes), null, "read"); PluginHandle connectivity = new PluginHandle("transfer", null, "Connectivity", "/ui/connectivity", ConnectivityPluginEndpoints.class, new ConnectivityPluginRegion(mapper, "soy.upena.page.connectivityPluginRegion", "soy.upena.page.connectionsHealth", "soy.upena.page.connectionOverview", renderer, upenaHealth, amzaService, upenaSSLConfig, upenaStore, healthPluginRegion, discoveredRoutes), null, "read"); PluginHandle changes = new PluginHandle("road", null, "Changes", "/ui/changeLog", ChangeLogPluginEndpoints.class, new ChangeLogPluginRegion("soy.upena.page.changeLogPluginRegion", renderer, upenaStore), null, "read"); PluginHandle instances = new PluginHandle("star", null, "Instances", "/ui/instances", InstancesPluginEndpoints.class, instancesPluginRegion, null, "read"); PluginHandle config = new PluginHandle("cog", null, "Config", "/ui/config", ConfigPluginEndpoints.class, new ConfigPluginRegion(mapper, "soy.upena.page.configPluginRegion", renderer, upenaSSLConfig, upenaStore, upenaConfigStore), null, "read"); PluginHandle repo = new PluginHandle("hdd", null, "Repository", "/ui/repo", RepoPluginEndpoints.class, new RepoPluginRegion("soy.upena.page.repoPluginRegion", renderer, upenaStore, localPathToRepo), null, "read"); PluginHandle projects = new PluginHandle("folder-open", null, "Projects", "/ui/projects", ProjectsPluginEndpoints.class, new ProjectsPluginRegion("soy.upena.page.projectsPluginRegion", "soy.upena.page.projectBuildOutput", "soy.upena.page.projectBuildOutputTail", renderer, upenaStore, localPathToRepo), null, "read"); PluginHandle users = new PluginHandle("user", null, "Users", "/ui/users", UsersPluginEndpoints.class, new UsersPluginRegion("soy.upena.page.usersPluginRegion", renderer, upenaStore), null, "read"); PluginHandle permissions = new PluginHandle("lock", null, "Permission", "/ui/permissions", PermissionsPluginEndpoints.class, new PermissionsPluginRegion("soy.upena.page.permissionsPluginRegion", renderer, upenaStore), null, "read"); PluginHandle clusters = new PluginHandle("cloud", null, "Clusters", "/ui/clusters", ClustersPluginEndpoints.class, new ClustersPluginRegion("soy.upena.page.clustersPluginRegion", renderer, upenaStore), null, "read"); PluginHandle hosts = new PluginHandle("tasks", null, "Hosts", "/ui/hosts", HostsPluginEndpoints.class, hostsPluginRegion, null, "read"); PluginHandle services = new PluginHandle("tint", null, "Services", "/ui/services", ServicesPluginEndpoints.class, new ServicesPluginRegion(mapper, "soy.upena.page.servicesPluginRegion", renderer, upenaStore), null, "read"); PluginHandle releases = new PluginHandle("send", null, "Releases", "/ui/releases", ReleasesPluginEndpoints.class, releasesPluginRegion, null, "read"); PluginHandle modules = new PluginHandle("wrench", null, "Modules", "/ui/modules", ModulesPluginEndpoints.class, new ModulesPluginRegion(mapper, repositoryProvider, "soy.upena.page.modulesPluginRegion", renderer, upenaStore), null, "read"); PluginHandle proxy = new PluginHandle("random", null, "Proxies", "/ui/proxy", ProxyPluginEndpoints.class, new ProxyPluginRegion("soy.upena.page.proxyPluginRegion", renderer), null, "read", "debug"); PluginHandle ring = new PluginHandle("leaf", null, "Upena", "/ui/ring", UpenaRingPluginEndpoints.class, new UpenaRingPluginRegion(storeMapper, "soy.upena.page.upenaRingPluginRegion", renderer, amzaService, upenaStore, upenaConfigStore), null, "read", "debug"); PluginHandle loadBalancer = new PluginHandle("scale", null, "Load Balancer", "/ui/loadbalancers", LoadBalancersPluginEndpoints.class, new LoadBalancersPluginRegion("soy.upena.page.loadBalancersPluginRegion", renderer, upenaStore, awsClientFactory), null, "read", "debug"); ServicesCallDepthStack servicesCallDepthStack = new ServicesCallDepthStack(); PerfService perfService = new PerfService(servicesCallDepthStack); PluginHandle profiler = new PluginHandle("hourglass", null, "Profiler", "/ui/profiler", ProfilerPluginEndpoints.class, new ProfilerPluginRegion("soy.upena.page.profilerPluginRegion", renderer, new VisualizeProfile(new NameUtils(), servicesCallDepthStack)), null, "read", "debug"); PluginHandle jvm = null; PluginHandle breakpointDumper = null; if (jvmapi != null) { jvm = new PluginHandle("camera", null, "JVM", "/ui/jvm", JVMPluginEndpoints.class, new JVMPluginRegion("soy.upena.page.jvmPluginRegion", renderer, upenaStore, jvmapi), null, "read", "debug"); breakpointDumper = new PluginHandle("record", null, "Breakpoint Dumper", "/ui/breakpoint", BreakpointDumperPluginEndpoints.class, new BreakpointDumperPluginRegion("soy.upena.page.breakpointDumperPluginRegion", renderer, upenaStore, jvmapi), null, "read", "debug"); } PluginHandle aws = null; aws = new PluginHandle("globe", null, "AWS", "/ui/aws", AWSPluginEndpoints.class, new AWSPluginRegion("soy.upena.page.awsPluginRegion", renderer, awsClientFactory), null, "read", "debug"); PluginHandle monkey = new PluginHandle("flash", null, "Chaos", "/ui/chaos", MonkeyPluginEndpoints.class, new MonkeyPluginRegion("soy.upena.page.monkeyPluginRegion", renderer, upenaStore), null, "read", "debug"); PluginHandle api = new PluginHandle("play-circle", null, "API", "/ui/api", ApiPluginEndpoints.class, null, null, "read", "debug"); PluginHandle thrown = new PluginHandle("equalizer", null, "Thrown", "/ui/thrown", ThrownPluginEndpoints.class, new ThrownPluginRegion(hostKey, "soy.upena.page.thrownPluginRegion", renderer, upenaStore), null, "read", "debug"); PluginHandle probe = new PluginHandle("hand-right", null, "Deployable", "/ui/deployable", ManagedDeployablePluginEndpoints.class, new ManagedDeployablePluginRegion(sessionStore, hostKey, "soy.upena.page.deployablePluginRegion", renderer, upenaStore, upenaSSLConfig, port), null, "read", "debug"); List<PluginHandle> plugins = new ArrayList<>(); plugins.add(auth); plugins.add(new PluginHandle(null, null, "API", null, null, null, "separator", "read")); plugins.add(api); plugins.add(new PluginHandle(null, null, "Build", null, null, null, "separator", "read")); plugins.add(repo); plugins.add(projects); plugins.add(modules); plugins.add(new PluginHandle(null, null, "Config", null, null, null, "separator", "read")); plugins.add(aws); plugins.add(changes); plugins.add(config); plugins.add(clusters); plugins.add(hosts); plugins.add(services); plugins.add(releases); plugins.add(instances); plugins.add(loadBalancer); plugins.add(new PluginHandle(null, null, "Health", null, null, null, "separator", "read")); plugins.add(health); plugins.add(connectivity); plugins.add(topology); plugins.add(new PluginHandle(null, null, "Tools", null, null, null, "separator", "read", "debug")); plugins.add(monkey); plugins.add(proxy); if (jvm != null) { plugins.add(jvm); plugins.add(thrown); plugins.add(breakpointDumper); } plugins.add(profiler); plugins.add(ring); plugins.add(users); plugins.add(permissions); jerseyEndpoints.addInjectable(SessionStore.class, sessionStore); jerseyEndpoints.addInjectable(UpenaSSLConfig.class, upenaSSLConfig); jerseyEndpoints.addInjectable(SoyService.class, soyService); jerseyEndpoints.addEndpoint(AsyncLookupEndpoints.class); jerseyEndpoints.addInjectable(AsyncLookupService.class, new AsyncLookupService(upenaSSLConfig, upenaStore)); jerseyEndpoints.addEndpoint(PerfServiceEndpoints.class); jerseyEndpoints.addInjectable(PerfService.class, perfService); for (PluginHandle plugin : plugins) { soyService.registerPlugin(plugin); if (plugin.separator == null) { jerseyEndpoints.addEndpoint(plugin.endpointsClass); if (plugin.region != null) { jerseyEndpoints.addInjectable(plugin.region.getClass(), plugin.region); } } } jerseyEndpoints.addEndpoint(probe.endpointsClass); jerseyEndpoints.addInjectable(probe.region.getClass(), probe.region); jerseyEndpoints.addInjectable(UnauthorizedPluginRegion.class, unauthorizedRegion); //jerseyEndpoints.addEndpoint(UpenaPropagatorEndpoints.class); }
From source file:com.haines.ml.rce.io.protostuff.ProtostuffEventMarshalBufferUnitTest.java
private Iterable<ByteBuffer> loadByteBuffersFromFile(String splitFileName) throws IOException { InputStream stream = ProtostuffEventMarshalBufferUnitTest.class .getResourceAsStream("/testBufferSplits/" + splitFileName); Iterable<String> bufferStrings = IOUtils.readLines(stream, Charset.defaultCharset()); return Iterables.transform(bufferStrings, new Function<String, ByteBuffer>() { @Override// w ww. j a v a 2s . c o m public ByteBuffer apply(String input) { Matcher matcher = BYTE_ARRAY_EXTRACTOR.matcher(input); // strip out everything except the bytes matcher.find(); input = matcher.group(1); String[] byteStrs = input.split(","); byte[] bytes = new byte[byteStrs.length]; for (int i = 0; i < byteStrs.length; i++) { bytes[i] = Byte.parseByte(byteStrs[i].trim()); } return ByteBuffer.wrap(bytes); } }); }
From source file:com.example.util.FileUtils.java
/** * Reads the contents of a file line by line to a List of Strings. * The file is always closed./*from ww w. j a v a 2 s. c o m*/ * * @param file the file to read, must not be {@code null} * @param encoding the encoding to use, {@code null} means platform default * @return the list of Strings representing each line in the file, never {@code null} * @throws IOException in case of an I/O error * @since 2.3 */ public static List<String> readLines(File file, Charset encoding) throws IOException { InputStream in = null; try { in = openInputStream(file); return IOUtils.readLines(in, Charsets.toCharset(encoding)); } finally { IOUtils.closeQuietly(in); } }
From source file:nl.knaw.huc.di.tag.tagml.importer.ImportDataTAGMLTest.java
private void processTAGMLFile(String basename) throws TAGMLSyntaxError { store.runInTransaction(() -> {/*from w w w . j a v a2 s. c om*/ try { InputStream input = getInputStream(basename); List<String> lines = IOUtils.readLines(input, Charset.defaultCharset()); LOG.info("\nTAGML:\n{}\n", String.join("\n", lines)); input = getInputStream(basename); printTokens(input); input = getInputStream(basename); LOG.info("testing data/tagml/{}.tagml", basename); LOG.info("importTAGML\n"); TAGDocument document = new TAGMLImporter(store).importTAGML(input); logDocumentGraph(document, ""); // generateLaTeX(basename, document); } catch (IOException e) { e.printStackTrace(); throw new UncheckedIOException(e); } }); }
From source file:nl.strohalm.cyclos.controls.ads.categories.ImportAdCategoriesAction.java
@Override @SuppressWarnings("unchecked") protected ActionForward executeAction(final ActionContext context) throws Exception { final ImportAdCategoriesForm form = context.getForm(); final LocalSettings localSettings = settingsService.getLocalSettings(); final FormFile upload = form.getUpload(); try {/*from w w w.j a va2 s . c o m*/ final List<String> lines = IOUtils.readLines(upload.getInputStream(), localSettings.getCharset()); final String xml = StringUtils.join(lines.iterator(), '\n'); adCategoryService.importFromXml(xml); context.sendMessage("adCategory.imported"); } catch (final PermissionDeniedException e) { // Rethrow when permission denied throw e; } catch (final Exception e) { context.sendMessage("adCategory.error.importing"); } finally { upload.destroy(); } return context.getSuccessForward(); }
From source file:nl.strohalm.cyclos.controls.settings.ImportSettingsAction.java
@Override @SuppressWarnings("unchecked") protected ActionForward executeAction(final ActionContext context) throws Exception { final ManageSettingsForm form = context.getForm(); final LocalSettings localSettings = settingsService.getLocalSettings(); final FormFile upload = form.getUpload(); final Collection<Setting.Type> types = CoercionHelper.coerceCollection(Setting.Type.class, List.class, form.getType());/*from w w w . j a va 2 s . c o m*/ try { final List<String> lines = IOUtils.readLines(upload.getInputStream(), localSettings.getCharset()); final String xml = StringUtils.join(lines.iterator(), '\n'); settingsService.importFromXml(xml, types); context.sendMessage("settings.imported"); } catch (final PermissionDeniedException e) { // Rethrow when permission denied throw e; } catch (final SelectedSettingTypeNotInFileException e) { final List<Type> notImportedTypes = e.getNotImportedTypes(); final List<String> names = new ArrayList<String>(); for (final Type type : notImportedTypes) { names.add(context.message("settings.type." + type.name())); } context.sendMessage("settings.error.selectedSettingTypeNotInFile", StringUtils.join(names.iterator(), "\n")); } catch (final Exception e) { context.sendMessage("settings.error.importing"); } finally { upload.destroy(); } if (types.contains(Setting.Type.MAIL_TRANSLATION) || types.contains(Setting.Type.MESSAGE)) { return context.findForward("manageTranslationMessages"); } else { return context.getSuccessForward(); } }
From source file:org.alex73.skarynka.scan.propsets.PropsetUtils.java
public static Map<String, Integer> getPropset(int propsetNumber) throws IOException { Map<String, Integer> result = new TreeMap<>(); try (InputStream in = PropsetUtils.class.getResourceAsStream("propset" + propsetNumber + ".lua")) { for (String line : IOUtils.readLines(in, "UTF-8")) { Matcher m = RE_PROP.matcher(line); if (m.matches()) { result.put(m.group(1), Integer.parseInt(m.group(2))); }// w w w . j av a2 s.co m } } return result; }
From source file:org.alfresco.repo.virtual.bundle.VirtualNodeServiceExtension.java
private List<AssociationRef> getDownloadTargetAssocs(NodeRef sourceNodeRef) { try {/* ww w . j a va 2 s. c om*/ List<AssociationRef> result = new ArrayList<AssociationRef>(); NodeRef tempFolderNodeRef = downloadAssociationsFolder.resolve(); if (tempFolderNodeRef == null) { return result; } String tempFileName = sourceNodeRef.getId(); NodeRef tempFileNodeRef = environment.getChildByName(tempFolderNodeRef, ContentModel.ASSOC_CONTAINS, tempFileName); if (tempFileNodeRef == null) { return result; } List<String> readLines = IOUtils.readLines(environment.openContentStream(tempFileNodeRef), StandardCharsets.UTF_8); for (String line : readLines) { NodeRef targetRef = new NodeRef(line); AssociationRef assocRef = new AssociationRef(sourceNodeRef, DownloadModel.ASSOC_REQUESTED_NODES, targetRef); result.add(assocRef); } return result; } catch (IOException e) { throw new VirtualizationException(e); } }
From source file:org.alfresco.repo.virtual.bundle.VirtualNodeServiceExtension.java
private void createDownloadAssociation(NodeRef sourceNodeRef, NodeRef targetRef) { NodeRef tempFolderNodeRef = downloadAssociationsFolder.resolve(true); String tempFileName = sourceNodeRef.getId(); NodeRef tempFileNodeRef = environment.getChildByName(tempFolderNodeRef, ContentModel.ASSOC_CONTAINS, tempFileName);/*from www .ja v a 2 s . c o m*/ if (tempFileNodeRef == null) { FileInfo newTempFileInfo = environment.create(tempFolderNodeRef, tempFileName, ContentModel.TYPE_CONTENT); tempFileNodeRef = newTempFileInfo.getNodeRef(); ContentWriter writer = environment.getWriter(tempFileNodeRef, ContentModel.PROP_CONTENT, true); writer.setMimetype("text/plain"); writer.putContent(targetRef.toString()); } else { ContentWriter writer = environment.getWriter(tempFileNodeRef, ContentModel.PROP_CONTENT, true); try { List<String> readLines = IOUtils.readLines(environment.openContentStream(tempFileNodeRef), StandardCharsets.UTF_8); String targetRefString = targetRef.toString(); if (!readLines.contains(targetRefString)) { readLines.add(targetRefString); } String text = ""; for (String line : readLines) { if (text.isEmpty()) { text = line; } else { text = text + IOUtils.LINE_SEPARATOR + line; } } writer.putContent(text); } catch (IOException e) { throw new ActualEnvironmentException(e); } } }