List of usage examples for org.springframework.core.io ClassPathResource getInputStream
@Override public InputStream getInputStream() throws IOException
From source file:org.springframework.sync.diffsync.DiffSyncTest.java
private String resource(String name) throws IOException { ClassPathResource resource = new ClassPathResource("/org/springframework/sync/" + name + ".json"); BufferedReader reader = new BufferedReader(new InputStreamReader(resource.getInputStream())); StringBuilder builder = new StringBuilder(); while (reader.ready()) { builder.append(reader.readLine()); }/*from w w w.j a v a2 s .c om*/ return builder.toString(); }
From source file:com.bgh.myopeninvoice.jsf.jsfbeans.InvoiceBean.java
public void runReportListener(ActionEvent event) throws IOException { if (selectedInvoiceEntity != null) { Map<String, Object> params = new HashMap<>(); params.put("p_invoice_id", selectedInvoiceEntity.getInvoiceId()); Date printDate = new DateTime().toDate(); String name = "INVOICE-" + selectedInvoiceEntity.getTitle() + "-" + new SimpleDateFormat("yyyyMMddHHmmss").format(printDate); ClassPathResource report1 = new ClassPathResource(Constants.REPORT_1); final byte[] bytes = IOUtils.toByteArray(report1.getInputStream()); final BIRTReport myReport = new BIRTReport(name, params, bytes, reportRunner); final ByteArrayOutputStream reportContent = myReport.runReport().getReportContent(); ReportsEntity report = new ReportsEntity(); report.setDateCreated(printDate); report.setInvoiceByInvoiceId(selectedInvoiceEntity); report.setContent(reportContent.toByteArray()); report.setReportName(name + ".pdf"); invoiceDAO.getReportsRepository().save(report); Faces.sendFile(reportContent.toByteArray(), name + ".pdf", true); FacesUtils.addSuccessMessage("Document has been generated"); } else {// w ww . j ava 2s .c o m FacesUtils.addErrorMessage("Selected invoice is null"); } }
From source file:nl.surfnet.coin.api.service.MockServiceImpl.java
@Override public GroupMembersEntry getGroupMembers(String groupId, String onBehalfOf, String spEntityId, Integer count, Integer startIndex, String sortBy) { if (isActive()) { return getPreparedGroupMembers(groupId); }/*from ww w . j a v a 2 s. c o m*/ ClassPathResource pathResource = new ClassPathResource(String.format(JSON_PATH, groupId, "teammembers")); if (!pathResource.exists()) { pathResource = new ClassPathResource(String.format(JSON_PATH, FALLBACK, "teammembers")); } try { GroupMembersEntry entry = parser.parseTeamMembers(pathResource.getInputStream()); processQueryOptions(entry, count, startIndex, sortBy, entry.getEntry()); return entry; } catch (IOException e) { throw new RuntimeException(e); } }
From source file:org.sakaiproject.sitestats.impl.event.FileEventRegistry.java
private void loadEventRegistryFile() { boolean customEventRegistryFileLoaded = false; // user-specified tool events definition if (customEventRegistryFile != null) { File customDefs = new File(customEventRegistryFile); if (customDefs.exists()) { FileInputStream in = null; try { LOG.info("init(): - loading custom event registry from: " + customDefs.getAbsolutePath()); in = new FileInputStream(customDefs); eventRegistry = DigesterUtil.parseToolEventsDefinition(in); customEventRegistryFileLoaded = true; } catch (Throwable t) { LOG.warn("init(): - trouble loading event registry from : " + customDefs.getAbsolutePath(), t); } finally { if (in != null) try { in.close();/* w w w. j a v a2 s . co m*/ } catch (IOException e) { LOG.warn("init(): - failed to close inputstream (event registry from : " + customDefs.getAbsolutePath() + ")"); } } } else { LOG.warn("init(): - custom event registry file not found: " + customDefs.getAbsolutePath()); } } // default tool events definition if (!customEventRegistryFileLoaded) { ClassPathResource defaultDefs = new ClassPathResource( "org/sakaiproject/sitestats/config/" + FileEventRegistry.TOOL_EVENTS_DEF_FILE); try { LOG.info("init(): - loading default event registry from: " + defaultDefs.getPath() + ". A custom one for adding/removing events can be specified in sakai.properties with the property: toolEventsDefinitionFile@org.sakaiproject.sitestats.api.StatsManager=${sakai.home}/toolEventsdef.xml."); eventRegistry = DigesterUtil.parseToolEventsDefinition(defaultDefs.getInputStream()); } catch (Throwable t) { LOG.error("init(): - trouble loading default event registry from : " + defaultDefs.getPath(), t); } } // add user-specified tool List<ToolInfo> additions = null; if (customEventRegistryAdditionsFile != null) { File customDefs = new File(customEventRegistryAdditionsFile); if (customDefs.exists()) { FileInputStream in = null; try { LOG.info("init(): - loading custom event registry additions from: " + customDefs.getAbsolutePath()); in = new FileInputStream(customDefs); additions = DigesterUtil.parseToolEventsDefinition(in); } catch (Throwable t) { LOG.warn("init(): - trouble loading custom event registry additions from : " + customDefs.getAbsolutePath(), t); } finally { if (in != null) try { in.close(); } catch (IOException e) { LOG.warn( "init(): - failed to close inputstream (custom event registry additions from : " + customDefs.getAbsolutePath() + ")"); } } } else { LOG.warn("init(): - custom event registry additions file not found: " + customDefs.getAbsolutePath()); } } if (additions != null) eventRegistry = EventUtil.addToEventRegistry(additions, false, eventRegistry); // remove user-specified tool and/or events List<ToolInfo> removals = null; if (customEventRegistryRemovalsFile != null) { File customDefs = new File(customEventRegistryRemovalsFile); if (customDefs.exists()) { FileInputStream in = null; try { LOG.info("init(): - loading custom event registry removals from: " + customDefs.getAbsolutePath()); in = new FileInputStream(customDefs); removals = DigesterUtil.parseToolEventsDefinition(in); } catch (Throwable t) { LOG.warn("init(): - trouble loading custom event registry removals from : " + customDefs.getAbsolutePath(), t); } finally { if (in != null) try { in.close(); } catch (IOException e) { LOG.warn("init(): - failed to close inputstream (custom event regitry removals from : " + customDefs.getAbsolutePath() + ")"); } } } else { LOG.warn( "init(): - custom event registry removals file not found: " + customDefs.getAbsolutePath()); } } if (removals != null) eventRegistry = EventUtil.removeFromEventRegistry(removals, eventRegistry); // debug: print resulting list // LOG.info("-------- Printing resulting eventRegistry list:"); // Iterator<ToolInfo> iT = eventRegistry.iterator(); // while(iT.hasNext()) LOG.info(iT.next().toString()); // LOG.info("------------------------------------------------------"); }
From source file:py.una.pol.karaku.reports.ExportReport.java
/** * Obtiene los parametros genericos para los reportes simples<br> * // w w w. j a v a 2s .c om * @return Lista de parametros generales que seran enviados al template * basico para los reportes */ private Map<String, Object> getDetailsReport(Map<String, Object> params) throws IOException { if (params != null) { ClassPathResource imagePath = new ClassPathResource(FILE_LOCATION_TEMPLATE + "logo.jpg"); params.put("logo", imagePath.getInputStream()); params.put("nombreInstitucion", getMessage("BASE_REPORT_NAME_INSTITUTION")); params.put("nombreEstablecimiento", getMessage("BASE_REPORT_NAME_ESTABLISHMENT")); params.put("date", getMessage("BASE_REPORT_DATE")); params.put("time", getMessage("BASE_REPORT_TIME")); params.put("selectionCriteria", getMessage("BASE_REPORT_SELECTION_CRITERIA")); params.put("user", getMessage("BASE_REPORT_USER")); params.put("userName", getUserName()); params.put("nameSystem", getNameSystem()); params.put("page", getMessage("BASE_REPORT_PAGE")); params.put("pageThe", getMessage("BASE_REPORT_PAGE_THE")); } return params; }
From source file:py.una.pol.karaku.reports.ExportReport.java
/** * * Metodo que compila un archivo .jrxml<br> * <b>Por ejemplo</b><br> * <ol>//from w w w . j av a 2s. c o m * <li><b>HolaMundo</b>, retorna [Hola,Mundo] * </ol> * * 1. fileReport.jrxml, retorna fileReport.jasper * * @param fileReport * @return * archivo compilado * * @throws ReportException */ public JasperReport compile(String fileReport) throws ReportException { try { ClassPathResource resource = new ClassPathResource(FILE_LOCATION + fileReport); return JasperCompileManager.compileReport(resource.getInputStream()); } catch (JRException e) { throw new ReportException(e); } catch (IOException e) { throw new ReportException(e); } }
From source file:org.surfnet.oaaas.auth.AuthorizationServerFilter.java
@Override public void init(FilterConfig filterConfig) throws ServletException { /*//from w w w . j a v a2 s. co m * First check on the presence of a init-param where to look for the properties to support * multiple resource servers in the same war. Then look for second best apis-resource-server.properties file, then * try to use the filter config if parameters are present. If this also * fails trust on the setters (e.g. probably in test modus), but apply * fail-fast strategy */ ClassPathResource res = null; String propertiesFile = filterConfig.getInitParameter("apis-resource-server.properties.file"); if (StringUtils.isNotEmpty(propertiesFile)) { res = new ClassPathResource(propertiesFile); } if (res == null || !res.exists()) { res = new ClassPathResource("apis-resource-server.properties"); } if (res != null && res.exists()) { Properties prop = new Properties(); try { prop.load(res.getInputStream()); } catch (IOException e) { throw new RuntimeException("Error in reading the apis-resource-server.properties file", e); } resourceServerKey = prop.getProperty("adminService.resourceServerKey"); resourceServerSecret = prop.getProperty("adminService.resourceServerSecret"); authorizationServerUrl = prop.getProperty("adminService.tokenVerificationUrl"); cacheEnabled = Boolean.valueOf(prop.getProperty("adminService.cacheEnabled")); String allowCorsRequestsProperty = prop.getProperty("adminService.allowCorsRequests"); if (StringUtils.isNotEmpty(allowCorsRequestsProperty)) { allowCorsRequests = Boolean.valueOf(allowCorsRequestsProperty); } String typeInformationIsIncludedProperty = prop.getProperty("adminService.jsonTypeInfoIncluded"); if (StringUtils.isNotEmpty(typeInformationIsIncludedProperty)) { typeInformationIsIncluded = Boolean.valueOf(typeInformationIsIncludedProperty); } } else if (filterConfig.getInitParameter("resource-server-key") != null) { resourceServerKey = filterConfig.getInitParameter("resource-server-key"); resourceServerSecret = filterConfig.getInitParameter("resource-server-secret"); authorizationServerUrl = filterConfig.getInitParameter("authorization-server-url"); typeInformationIsIncluded = Boolean .valueOf(filterConfig.getInitParameter("type-information-is-included")); } Assert.hasText(resourceServerKey, "Must provide a resource server key"); Assert.hasText(resourceServerSecret, "Must provide a resource server secret"); Assert.hasText(authorizationServerUrl, "Must provide a authorization server url"); this.authorizationValue = new String( Base64.encodeBase64(resourceServerKey.concat(":").concat(resourceServerSecret).getBytes())); if (cacheAccessTokens()) { this.cache = buildCache(); Assert.notNull(this.cache); } this.client = createClient(); this.objectMapper = createObjectMapper(typeInformationIsIncluded); }
From source file:com.loy.MainFrame.java
@SuppressWarnings("rawtypes") public void init() { String src = "ee.png"; try {//from www.jav a2 s .com ClassPathResource classPathResource = new ClassPathResource(src); image = ImageIO.read(classPathResource.getURL()); this.setIconImage(image); } catch (IOException e) { } menu = new JMenu("LOG CONSOLE"); this.jmenuBar = new JMenuBar(); this.jmenuBar.add(menu); panel = new JPanel(new BorderLayout()); this.add(panel); ClassPathResource classPathResource = new ClassPathResource("application.yml"); Yaml yaml = new Yaml(); Map result = null; try { result = (Map) yaml.load(classPathResource.getInputStream()); } catch (IOException e1) { e1.printStackTrace(); } String platformStr = result.get("platform").toString(); String version = result.get("version").toString(); String jvmOption = result.get("jvmOption").toString(); @SuppressWarnings("unchecked") List<String> projects = (List<String>) result.get("projects"); platform = Platform.valueOf(platformStr); final Runtime runtime = Runtime.getRuntime(); File pidsForder = new File("./pids"); if (!pidsForder.exists()) { pidsForder.mkdir(); } else { File[] files = pidsForder.listFiles(); if (files != null) { for (File f : files) { f.deleteOnExit(); String pidStr = f.getName(); try { Long pid = new Long(pidStr); if (Processes.isProcessRunning(platform, pid)) { if (Platform.Windows == platform) { Processes.tryKillProcess(null, platform, new NullProcessor(), pid); } else { Processes.killProcess(null, platform, new NullProcessor(), pid); } } } catch (Exception ex) { } } } } File currentForder = new File(""); String rootPath = currentForder.getAbsolutePath(); rootPath = rootPath.replace(File.separator + "build" + File.separator + "libs", ""); rootPath = rootPath.replace(File.separator + "e-example-ms-start-w", ""); for (String value : projects) { String path = value; String[] values = value.split("/"); value = values[values.length - 1]; String appName = value; value = rootPath + "/" + path + "/build/libs/" + value + "-" + version + ".jar"; JMenuItem menuItem = new JMenuItem(appName); JTextArea textArea = new JTextArea(); textArea.setVisible(true); textArea.setLineWrap(true); textArea.setWrapStyleWord(true); textArea.setAutoscrolls(true); JScrollPane scorll = new JScrollPane(textArea); this.textSreaMap.put(appName, scorll); EComposite ecomposite = new EComposite(); ecomposite.setCommand(value); ecomposite.setTextArea(textArea); composites.put(appName, ecomposite); menuItem.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Collection<JScrollPane> values = textSreaMap.values(); for (JScrollPane t : values) { t.setVisible(false); } String actions = e.getActionCommand(); JScrollPane textArea = textSreaMap.get(actions); if (textArea != null) { textArea.setVisible(true); panel.removeAll(); panel.add(textArea); panel.repaint(); panel.validate(); self.repaint(); self.validate(); } } }); menu.add(menuItem); } new Thread(new Runnable() { @Override public void run() { int size = composites.keySet().size(); int index = 1; for (String appName : composites.keySet()) { EComposite composite = composites.get(appName); try { Process process = runtime.exec( "java " + jvmOption + " -Dfile.encoding=UTF-8 -jar " + composite.getCommand()); Long pid = Processes.processId(process); pids.add(pid); File pidsFile = new File("./pids", pid.toString()); pidsFile.createNewFile(); new WriteLogThread(process.getInputStream(), composite.getTextArea()).start(); } catch (IOException e) { e.printStackTrace(); } synchronized (lock) { try { if (index < size) { lock.wait(); } else { index++; } } catch (InterruptedException e) { e.printStackTrace(); } } } } }).start(); }