List of usage examples for org.springframework.util FileCopyUtils copyToByteArray
public static byte[] copyToByteArray(@Nullable InputStream in) throws IOException
From source file:org.spring.resource.FileSourceExample.java
public static void main(String[] args) { try {//from w ww .j a v a2 s . c o m String filePath = "E:\\JEELearning\\ideaworlplace\\springdream\\springdream.ioc\\src\\main\\resources\\FileSource.txt"; // ? Resource res1 = new FileSystemResource(filePath); // ? Resource res2 = new ClassPathResource("FileSource.txt"); System.out.println("?:" + res1.getFilename()); System.out.println("?:" + res2.getFilename()); InputStream in1 = res1.getInputStream(); InputStream in2 = res2.getInputStream(); // System.out.println("?:" + read(in1)); // System.out.println("?:" + read(in2)); System.out.println("?:" + new String(FileCopyUtils.copyToByteArray(in1))); System.out.println("?:" + new String(FileCopyUtils.copyToByteArray(in2))); } catch (IOException e) { e.printStackTrace(); } }
From source file:biz.c24.io.spring.integration.test.TestUtils.java
public static byte[] loadXmlBytes() throws Exception { ClassPathResource resource = new ClassPathResource("valid-XML-1.xml"); byte[] valid1 = FileCopyUtils.copyToByteArray(resource.getInputStream()); return valid1; }
From source file:biz.c24.io.spring.integration.test.TestUtils.java
public static byte[] loadCsvBytes() throws Exception { ClassPathResource resource = new ClassPathResource("valid-1.txt"); byte[] valid1 = FileCopyUtils.copyToByteArray(resource.getInputStream()); return valid1; }
From source file:biz.c24.io.spring.integration.test.TestUtils.java
public static byte[] loadJsonBytes() throws Exception { ClassPathResource resource = new ClassPathResource("valid-1.json"); byte[] valid1 = FileCopyUtils.copyToByteArray(resource.getInputStream()); return valid1; }
From source file:be.vlaanderen.sesam.monitor.internal.util.BodyUtils.java
public static ChannelBuffer fileToBuffer(File f) throws IOException { FileInputStream fis = new FileInputStream(f); byte[] buf = FileCopyUtils.copyToByteArray(fis); ChannelBuffer wcb = ChannelBuffers.wrappedBuffer(buf); return wcb;/*from ww w.j a va 2 s. c o m*/ }
From source file:net.solarnetwork.node.hw.currentcost.test.CCMessageParserTest.java
@Test public void praseClassicMessageWithHistory() throws IOException { byte[] xml = FileCopyUtils.copyToByteArray(getClass().getResourceAsStream("message-1.xml")); CCMessageParser parser = new CCMessageParser(); CCDatum datum = parser.parseMessage(xml); assertNotNull(datum);//from w w w . j a v a 2s. co m log.debug("Got CCDatum: " + datum.getStatusMessage()); assertEquals("channel1Watts value", Integer.valueOf(114), datum.getChannel1Watts()); assertEquals("channel2Watts value", Integer.valueOf(2), datum.getChannel2Watts()); assertEquals("channel3Watts value", Integer.valueOf(103), datum.getChannel3Watts()); assertEquals("daysSinceBegin value", Integer.valueOf(6), datum.getDaysSinceBegin()); assertEquals("02198", datum.getDeviceAddress()); assertEquals("CC02", datum.getDeviceName()); assertEquals("0.07", datum.getDeviceSoftwareVersion()); assertEquals("1", datum.getDeviceType()); assertNotNull("temperature", datum.getTemperature()); assertEquals("temperature value", 22.6, datum.getTemperature().doubleValue(), 0.01); assertEquals(new LocalTime(10, 43, 49), datum.getTime()); }
From source file:com.consol.citrus.functions.core.ReadFileResourceFunction.java
@Override public String execute(List<String> parameterList, TestContext context) { if (CollectionUtils.isEmpty(parameterList)) { throw new InvalidFunctionUsageException("Missing file path function parameter"); }/* ww w . j av a2 s .co m*/ boolean base64 = parameterList.size() > 1 ? Boolean.valueOf(parameterList.get(1)) : false; try { if (base64) { return Base64.encodeBase64String(FileCopyUtils.copyToByteArray( FileUtils.getFileResource(parameterList.get(0), context).getInputStream())); } else { return context.replaceDynamicContentInString( FileUtils.readToString(FileUtils.getFileResource(parameterList.get(0), context))); } } catch (IOException e) { throw new CitrusRuntimeException("Failed to read file", e); } }
From source file:com.wavemaker.commons.io.AbstractFileContent.java
@Override public byte[] asBytes() throws ResourceException { try {/*www. ja va2s .c o m*/ return FileCopyUtils.copyToByteArray(asInputStream()); } catch (IOException e) { throw new ResourceException(e); } }
From source file:biz.c24.io.spring.integration.samples.transform.TransformTest.java
byte[] loadCsvBytes() throws Exception { ClassPathResource resource = new ClassPathResource("valid-1.txt", this.getClass()); byte[] valid1 = FileCopyUtils.copyToByteArray(resource.getInputStream()); return valid1; }
From source file:com.axis.common.MockMultipartFile.java
/** * Create a new MockMultipartFile with the given content. * @param name the name of the file/*from w w w . j a v a 2 s. c o m*/ * @param contentStream the content of the file as stream * @throws IOException if reading from the stream failed */ public MockMultipartFile(String name, InputStream contentStream) throws IOException { this(name, "", null, FileCopyUtils.copyToByteArray(contentStream)); }