List of usage examples for org.springframework.core.io ByteArrayResource ByteArrayResource
public ByteArrayResource(byte[] byteArray, @Nullable String description)
From source file:com.sxthsenseapp.api.s3propertyloader.S3ResourceLoader.java
public Resource getResource(String location) { try {// w ww .j a v a2s.com S3Path s3Path = parseS3Path(location); S3Object s3Object = s3Service.getObject(s3Path.bucket, s3Path.key); byte[] buf = readS3Object(s3Object); return new ByteArrayResource(buf, location); } catch (Exception e) { throw new S3ResourceException("could not load resource from " + location, e); } }
From source file:org.web4thejob.context.DefaultSessionContext.java
protected void loadBeanDefinitions(final XmlBeanDefinitionReader reader) throws UnsupportedEncodingException { final List<PanelDefinition> panels = ContextUtil.getDRS().getAll(PanelDefinition.class); final Set<Resource> resources = new HashSet<Resource>(); for (final PanelDefinition panel : panels) { final Resource resource = new ByteArrayResource(panel.getDefinition().getBytes("UTF-8"), panel.getName());//from w w w.ja va 2 s . c o m resources.add(resource); } reader.loadBeanDefinitions(resources.toArray(new Resource[resources.size()])); }
From source file:org.hdiv.web.servlet.view.freemarker.FreeMarkerConfigurerTests.java
public void testFreemarkerConfigurationFactoryBeanWithNonFileResourceLoaderPath() throws IOException, TemplateException { FreeMarkerConfigurationFactoryBean fcfb = new FreeMarkerConfigurationFactoryBean(); fcfb.setTemplateLoaderPath("file:/mydir"); Properties settings = new Properties(); settings.setProperty("localized_lookup", "false"); fcfb.setFreemarkerSettings(settings); fcfb.setResourceLoader(new ResourceLoader() { public Resource getResource(String location) { if (!("file:/mydir".equals(location) || "file:/mydir/test".equals(location))) { throw new IllegalArgumentException(location); }// ww w.ja v a 2 s .co m return new ByteArrayResource("test".getBytes(), "test"); } public ClassLoader getClassLoader() { return getClass().getClassLoader(); } }); fcfb.afterPropertiesSet(); assertTrue(fcfb.getObject() instanceof Configuration); Configuration fc = (Configuration) fcfb.getObject(); Template ft = fc.getTemplate("test"); assertEquals("test", FreeMarkerTemplateUtils.processTemplateIntoString(ft, new HashMap())); }
From source file:org.surfnet.oaaas.auth.AuthorizationServerFilterTest.java
private MockFilterChain doCallFilter(VerifyTokenResponse recorderdResponse, MockHttpServletResponse response) throws IOException, ServletException { return doCallFilter( new Resource[] { new ByteArrayResource(mapper.writeValueAsString(recorderdResponse).getBytes(), "json") }, response);// ww w. j a va 2s . co m }
From source file:org.apache.geode.management.internal.web.util.ConvertUtils.java
/** * Converts the 2-dimensional byte array of file data, which includes the name of the file as * bytes followed by the byte content of the file, for all files being transmitted by Gfsh to the * GemFire Manager.//from w w w. j ava 2 s . c o m * <p/> * * @param fileData a 2 dimensional byte array of files names and file content. * @return an array of Spring Resource objects encapsulating the details (name and content) of * each file being transmitted by Gfsh to the GemFire Manager. * @see org.springframework.core.io.ByteArrayResource * @see org.springframework.core.io.Resource * @see org.apache.geode.management.internal.cli.CliUtil#bytesToData(byte[][]) * @see org.apache.geode.management.internal.cli.CliUtil#bytesToNames(byte[][]) */ public static Resource[] convert(final byte[][] fileData) { if (fileData == null) { return new Resource[0]; } final String[] fileNames = CliUtil.bytesToNames(fileData); final byte[][] fileContent = CliUtil.bytesToData(fileData); final List<Resource> resources = new ArrayList<Resource>(fileNames.length); for (int index = 0; index < fileNames.length; index++) { final String filename = fileNames[index]; resources.add(new ByteArrayResource(fileContent[index], String.format("Contents of JAR file (%1$s).", filename)) { @Override public String getFilename() { return filename; } }); } return resources.toArray(new Resource[resources.size()]); }
From source file:org.codehaus.groovy.grails.web.pages.GroovyPagesTemplateEngine.java
/** * Creates a Template using the given text for the Template and the given name. The name * of the template is required/*from w ww.j a v a 2s . c om*/ * * @param txt The URI of the page to create the template for * @param pageName The name of the page being parsed * * @return The Template instance * @throws CompilationFailedException * @throws IOException Thrown if an IO exception occurs creating the Template */ public Template createTemplate(String txt, String pageName) throws IOException { Assert.hasLength(txt, "Argument [txt] cannot be null or blank"); Assert.hasLength(pageName, "Argument [pageName] cannot be null or blank"); return createTemplate(new ByteArrayResource(txt.getBytes("UTF-8"), pageName), pageName); }
From source file:org.grails.gsp.GroovyPagesTemplateEngine.java
/** * Creates a Template using the given text for the Template and the given name. The name * of the template is required//from w w w . j a v a 2 s. c o m * * @param txt The URI of the page to create the template for * @param pageName The name of the page being parsed * * @return The Template instance * @throws CompilationFailedException * @throws IOException Thrown if an IO exception occurs creating the Template */ public Template createTemplate(String txt, String pageName) throws IOException { Assert.hasLength(txt, "Argument [txt] cannot be null or blank"); Assert.hasLength(pageName, "Argument [pageName] cannot be null or blank"); return createTemplate(new ByteArrayResource(txt.getBytes("UTF-8"), pageName), pageName, pageName != null); }
From source file:org.jahia.services.content.JCRStoreService.java
public void reloadNodeTypeRegistry() throws RepositoryException { List<String> filesList = new ArrayList<>(); List<String> remfiles; NodeTypeRegistry instance = NodeTypeRegistry.getInstance(); logger.info("Loading all CNDs from DB .."); remfiles = new ArrayList<>(nodeTypesDBService.getFilesList()); List<String> reloadedSystemIds = new ArrayList<>(); while (!remfiles.isEmpty() && !remfiles.equals(filesList)) { filesList = new ArrayList<>(remfiles); remfiles.clear();//w w w.j a va 2 s .c o m for (final String file : filesList) { try { if (file.endsWith(".cnd")) { final String cndFile = nodeTypesDBService.readFile(file); final String systemId = StringUtils.substringBeforeLast(file, ".cnd"); if (!initializedSystemIds.contains(systemId)) { logger.debug("Loading CND : {}", file); instance.addDefinitionsFile(new ByteArrayResource(cndFile.getBytes("UTF-8"), file), systemId); } reloadedSystemIds.add(systemId); } } catch (ParseException | NoSuchNodeTypeException e) { logger.debug(file + " cannot be parsed, reorder later"); remfiles.add(file); } catch (IOException e) { logger.error("Cannot parse CND file from DB : " + file, e); } } } List<String> systemIds = NodeTypeRegistry.getInstance().getSystemIds(); systemIds.removeAll(reloadedSystemIds); for (String systemId : systemIds) { NodeTypeRegistry.getInstance().unregisterNodeTypes(systemId); } if (!remfiles.isEmpty()) { logger.error("Cannot read CND from : " + remfiles); } registerNamespaces(); }
From source file:org.springframework.data.hadoop.serialization.MultiResourceSerializationFormat.java
/** * Reads Spring {@link Resource}s from an <code>Avro</code> container file. *//*from w ww . ja v a 2s . c o m*/ @Override protected SerializationReaderSupport createReader(final String location) { return new SerializationReaderSupport() { /* Native Avro reader. */ DataFileStream<GenericRecord> reader; @Override protected Closeable doOpen() throws IOException { final Resource hdfsResource = getHdfsResourceLoader().getResource(location); final InputStream inputStream = hdfsResource.getInputStream(); reader = new DataFileStream<GenericRecord>(inputStream, new GenericDatumReader<GenericRecord>()); return reader; } @Override protected Resource doRead() throws IOException { if (!reader.hasNext()) { return null; } final GenericRecord genericRecord = reader.next(); String description = ((Utf8) genericRecord.get(RESOURCE_KEY_FIELD)).toString(); byte[] content = ((ByteBuffer) genericRecord.get(RESOURCE_CONTENT_FIELD)).array(); return new ByteArrayResource(content, description); } }; }