Package org.apache.commons.io.output

Examples of org.apache.commons.io.output.ByteArrayOutputStream


     * @return the requested byte array
     * @throws NullPointerException if the input is null
     * @throws IOException if an I/O error occurs
     */
    public static byte[] toByteArray(InputStream input) throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        copy(input, output);
        return output.toByteArray();
    }
View Full Code Here


     * @return the requested byte array
     * @throws NullPointerException if the input is null
     * @throws IOException if an I/O error occurs
     */
    public static byte[] toByteArray(Reader input) throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        copy(input, output);
        return output.toByteArray();
    }
View Full Code Here

     * @throws IOException if an I/O error occurs
     * @since Commons IO 1.1
     */
    public static byte[] toByteArray(Reader input, String encoding)
            throws IOException {
        ByteArrayOutputStream output = new ByteArrayOutputStream();
        copy(input, output, encoding);
        return output.toByteArray();
    }
View Full Code Here

public class EmbedderMonitorBehaviour {

    @Test
    public void shouldNotPrintWithSilentMonitor() throws Throwable {
        OutputStream out = new ByteArrayOutputStream();
        SilentEmbedderMonitor monitor = new SilentEmbedderMonitor(new PrintStream(out));
        monitor.print("a message");
        monitor.printStackTrace(new RuntimeException());
        assertThat(out.toString(), is(""));
    }
View Full Code Here

        assertThat(out.toString(), is(""));
    }

    @Test
    public void shouldOnlyPrintFailuresWithReportingFailuresMonitor() throws Throwable {
        OutputStream out = new ByteArrayOutputStream();
        ReportingFailuresEmbedderMonitor monitor = new ReportingFailuresEmbedderMonitor(new PrintStream(out));
        monitor.runningEmbeddable("embeddable");
        monitor.runningStory("/path");
        monitor.generatingReportsView(new File("target"), Arrays.asList(Format.HTML.name()), new Properties());
        monitor.reportsViewGenerated(new ReportsCount(1, 0, 1, 2, 1, 0, 1, 1));
        assertThat(out.toString(), is(""));
        monitor.batchFailed(new BatchFailures());
        monitor.storyFailed("/path", new RuntimeException());
        assertThat(out.toString(), is(not("")));
   }
View Full Code Here

        ExamplesTableFactory factory = new ExamplesTableFactory(parameterConverters);

        // When
        String tableAsString = "|one|two|\n|11|12|\n|21|22|\n";
        ExamplesTable table = factory.createExamplesTable(tableAsString);
        OutputStream out = new ByteArrayOutputStream();
        PrintStream output = new PrintStream(out);
        table.outputTo(output);

        // Then
        assertThat(out.toString(), equalTo(tableAsString));
    }
View Full Code Here

     * @return the requested byte array
     * @throws NullPointerException if the input is null
     * @throws IOException if an I/O error occurs
     */
    public static byte[] toByteArray(final InputStream input) throws IOException {
        final ByteArrayOutputStream output = new ByteArrayOutputStream();
        copy(input, output);
        return output.toByteArray();
    }
View Full Code Here

     * @throws NullPointerException if the input is null
     * @throws IOException if an I/O error occurs
     * @since 2.3
     */
    public static byte[] toByteArray(final Reader input, final Charset encoding) throws IOException {
        final ByteArrayOutputStream output = new ByteArrayOutputStream();
        copy(input, output, encoding);
        return output.toByteArray();
    }
View Full Code Here

   * @Description: 账号数据导出Excel下载
   */
  public InputStream getUserExcel() throws
    IllegalArgumentException, IOException, IllegalAccessException
  {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    List<String[]> headNames = new ArrayList<String[]>();
    headNames.add(new String[] { "用户名", "密码", "电子邮件", "类型", "角色", "所属商家" });
    List<String[]> fieldNames = new ArrayList<String[]>();
    fieldNames.add(new String[] { "userName", "pwd", "email", "typeStr", "roleStr", "merchantStr"});

    ExportSetInfo setInfo = new ExportSetInfo();
    setInfo.setObjsMap(userService.getExportData());
    setInfo.setFieldNames(fieldNames);
    setInfo.setTitles(new String[] { "馋八戒后台用户信息" });
    setInfo.setHeadNames(headNames);
    setInfo.setOut(baos);
   
    // 将需要导出的数据输出到baos
    ExcelUtil.export2Excel(setInfo);
   
    return new ByteArrayInputStream(baos.toByteArray());
  }
View Full Code Here

   * @Description: 商家数据导出Excel下载
   */
  public InputStream getMerchantExcel() throws
    IllegalArgumentException, IOException, IllegalAccessException
  {
    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    List<String[]> headNames = new ArrayList<String[]>();
    List<String[]> fieldNames = new ArrayList<String[]>();
    headNames.add(new String[] { "商家名称", "商家电话", "商家邮箱", "商家地址",
        "加盟时间", "商家Logo", "法定代表人", "法定人身份证号码", "法定人电话",
        "法定人家庭地址", "法定人现居地址" });
    fieldNames.add(new String[]{"merchantName", "merchantPhone","merchantEmail",
        "merchantAddress","merchantJoinTime", "merchantLogoUrl","legalName",
        "legalIdCard","legalPhone","legalHomeAddress","legalAddress"});
   
    ExportSetInfo setInfo = new ExportSetInfo();
    setInfo.setObjsMap(merchantService.getExportData());
    setInfo.setFieldNames(fieldNames);
    setInfo.setTitles(new String[] { "馋八戒加盟商家信息" });
    setInfo.setHeadNames(headNames);
    setInfo.setOut(baos);
   
    // 将需要导出的数据输出到baos
    ExcelUtil.export2Excel(setInfo);
   
    return new ByteArrayInputStream(baos.toByteArray());
  }
View Full Code Here

TOP

Related Classes of org.apache.commons.io.output.ByteArrayOutputStream

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.