當前位置: 首頁>>代碼示例>>Java>>正文


Java IOUtils類代碼示例

本文整理匯總了Java中org.apache.poi.util.IOUtils的典型用法代碼示例。如果您正苦於以下問題:Java IOUtils類的具體用法?Java IOUtils怎麽用?Java IOUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IOUtils類屬於org.apache.poi.util包,在下文中一共展示了IOUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: process

import org.apache.poi.util.IOUtils; //導入依賴的package包/類
/**
 * could be interesting for spring batch
 *
 * @param inputResource source of the data read by lines
 * @param outputResource generated .xlsx resource
 */
public void process(Resource inputResource, Resource outputResource) {
    SXSSFWorkbook wb = new SXSSFWorkbook(flushSize);
    try {
        wb.setCompressTempFiles(true); // temp files will be gzipped
        final Sheet sh = wb.createSheet();

        InputStreamReader is = new InputStreamReader(inputResource.getInputStream());
        BufferedReader br = new BufferedReader(is);
        final CreationHelper createHelper = sh.getWorkbook().getCreationHelper();

        br.lines().forEachOrdered(string -> createRow(string, sh, createHelper));

        FileOutputStream out = new FileOutputStream(outputResource.getFile());

        wb.write(out);
        IOUtils.closeQuietly(out);
    } catch (IOException e) {
       logger.error("IOE", e);
    } finally {
        if (wb != null) {
            // dispose of temporary files backing this workbook on disk
            wb.dispose();
        }
    }
}
 
開發者ID:To-da,項目名稱:spring-boot-examples,代碼行數:32,代碼來源:PoiExcelWriter.java

示例2: filesZip

import org.apache.poi.util.IOUtils; //導入依賴的package包/類
@RequestMapping(value = "/files.zip")
@ResponseBody
byte[] filesZip() throws IOException {
    File dir = new File("./");
    File[] filesArray = dir.listFiles();
    if (filesArray == null || filesArray.length == 0)
        System.out.println(dir.getAbsolutePath() + " have no file!");
    ByteArrayOutputStream bo = new ByteArrayOutputStream();
    ZipOutputStream zipOut= new ZipOutputStream(bo);
    for(File xlsFile:filesArray){
        if(!xlsFile.isFile())continue;
        ZipEntry zipEntry = new ZipEntry(xlsFile.getName());
        zipOut.putNextEntry(zipEntry);
        zipOut.write(IOUtils.toByteArray(new FileInputStream(xlsFile)));
        zipOut.closeEntry();
    }
    zipOut.close();
    return bo.toByteArray();
}
 
開發者ID:Yuiffy,項目名稱:file-download-upload-zip-demo,代碼行數:20,代碼來源:FileController.java

示例3: addAndPersistProduct

import org.apache.poi.util.IOUtils; //導入依賴的package包/類
/**
 * ## todo : add proper mapping.
 *
 * @param request {@link HttpServletRequest}
 */
@PostMapping("add/product")
public Map<String, Boolean> addAndPersistProduct(final HttpServletRequest request) {
	final MultipartFile product = ((StandardMultipartHttpServletRequest) request).getMultiFileMap().getFirst("products");
	final MultipartFile image = ((StandardMultipartHttpServletRequest) request).getMultiFileMap().getFirst("images");

	// manually replace quote char
	final String commaSeparatedKeywords = request.getParameter("keywords").replaceAll("\"", "");
	final String userName = request.getParameter("username");

	final UserEntity userEntity = this.service.getUserByUserName(userName);
	final List<KeywordEntity> keywordEntityList = this.service.getKeywordEntityListByAlias(commaSeparatedKeywords);
	final ProductEntity productEntity = new ProductEntity();

	// manually replace quote char
	productEntity.setName(request.getParameter("name").replaceAll("\"", ""));
	productEntity.setDescription(request.getParameter("description").replaceAll("\"", ""));

	try (final InputStream imgInput = image.getInputStream();
			final InputStream cntInput = product.getInputStream()) {
		final byte[] imgArray = IOUtils.toByteArray(imgInput); // Apache commons IO.
		productEntity.setPreviewImage(imgArray);

		final byte[] cntArray = IOUtils.toByteArray(cntInput); // Apache commons IO.
		productEntity.setProductItem(cntArray);
	} catch (IOException e) {
		LOG.error(e.getMessage(), e);
	}

	productEntity.setUserEntity(userEntity);
	productEntity.setKeywordEntityList(keywordEntityList);

	this.service.persistProductEntity(productEntity);
	final Map<String, Boolean> returnMap = new HashMap<>();
	returnMap.put("success", productEntity.getProductUuid() != null);
	return returnMap;
}
 
開發者ID:inspectIT,項目名稱:marketplace,代碼行數:42,代碼來源:DetailsController.java

示例4: download

import org.apache.poi.util.IOUtils; //導入依賴的package包/類
public static void download(String from, String to) {
	InputStream in = null;
	OutputStream out = null;
	try {
		URL apdf = new URL(from);
		in = apdf.openStream();
		System.out.println("開始下載:" + from);
		out = new FileOutputStream(new File(to));
		IOUtils.copy(in, out);
		out.flush();
		System.out.println("下載完成:" + to);
	} catch (Exception e) {
		e.printStackTrace();
	} finally {
		try {
			if (in != null) {
				in.close();
			}
			if (out != null) {
				out.close();
			}
		} catch (Exception e2) {
			e2.printStackTrace();
		}
	}
}
 
開發者ID:bdceo,項目名稱:bd-codes,代碼行數:27,代碼來源:Download.java

示例5: create

import org.apache.poi.util.IOUtils; //導入依賴的package包/類
/**
 * @param inp
 * @param excelReader
 * @param ignoreNumFormat 是否忽略數據格式  (default=false,按照格式讀取) 
 * @return  jie
 * @throws InvalidFormatException
 * @throws IOException
 * @throws SQLException
 */
public static ReadHandler create(InputStream inp,
		ExcelReadListener excelReader, boolean ignoreNumFormat)
		throws InvalidFormatException, IOException, SQLException {
	 // If clearly doesn't do mark/reset, wrap up
       if (! inp.markSupported()) {
           inp = new PushbackInputStream(inp, 8);
       }

       // Ensure that there is at least some data there
       byte[] header8 = IOUtils.peekFirst8Bytes(inp);

       // Try to create
       if (POIFSFileSystem.hasPOIFSHeader(header8)) {
           POIFSFileSystem fs = new POIFSFileSystem(inp);
           return create(fs, excelReader, ignoreNumFormat);
       }
       if (POIXMLDocument.hasOOXMLHeader(inp)) {
            OPCPackage pkg = OPCPackage.open(inp);
            return create(pkg, excelReader, ignoreNumFormat);
       }
       throw new InvalidFormatException("Your InputStream was neither an OLE2 stream, nor an OOXML stream");
   

}
 
開發者ID:bingyulei007,項目名稱:bingexcel,代碼行數:34,代碼來源:ExcelReaderFactory.java

示例6: getTemplate

import org.apache.poi.util.IOUtils; //導入依賴的package包/類
@RequestMapping(value = "/emp/myview/downloadTemplate.do", method = RequestMethod.GET)
public void getTemplate(HttpServletRequest request,
                        HttpServletResponse response) {
    ClassLoader classLoader = this.getClass().getClassLoader();
    URL url = null;
    File file = null;
    FileInputStream fStream = null;
    try {
        url = classLoader.getResource("ProjectDescription.xlsx");
        file = new File(url.getPath());
        fStream = new FileInputStream(file);
        String headerValue = String.format("attachment; filename=\"%s\"",
                file.getName());
        response.setHeader("Content-Disposition", headerValue);
        response.setContentLength((int) file.length());
        response.setContentType(context.getMimeType(url.getPath()));
        org.apache.commons.io.IOUtils.copy(fStream,
                response.getOutputStream());
        response.flushBuffer();
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
開發者ID:devintqa,項目名稱:pms,代碼行數:25,代碼來源:FileUploadController.java

示例7: getItemDescriptionTemplate

import org.apache.poi.util.IOUtils; //導入依賴的package包/類
@RequestMapping(value = "/emp/myview/downloadItemDescTemplate.do", method = RequestMethod.GET)
public void getItemDescriptionTemplate(HttpServletRequest request,
                                       HttpServletResponse response) {
    ClassLoader classLoader = this.getClass().getClassLoader();
    URL url = null;
    File file = null;
    FileInputStream fStream = null;
    try {
        url = classLoader.getResource("ItemDescription.xlsx");
        file = new File(url.getPath());
        fStream = new FileInputStream(file);
        String headerValue = String.format("attachment; filename=\"%s\"",
                file.getName());
        response.setHeader("Content-Disposition", headerValue);
        response.setContentLength((int) file.length());
        response.setContentType(context.getMimeType(url.getPath()));
        org.apache.commons.io.IOUtils.copy(fStream,
                response.getOutputStream());
        response.flushBuffer();
    } catch (Exception e) {
        e.printStackTrace();
    }

}
 
開發者ID:devintqa,項目名稱:pms,代碼行數:25,代碼來源:FileUploadController.java

示例8: isNewExcelFormat

import org.apache.poi.util.IOUtils; //導入依賴的package包/類
/**
 * Detect the excel format with only peeking at the first 8 bytes of the input stream (leaving the stream untouched).
 *
 * @param inputStream the xls input stream.
 * @return true if the given input stream is a xls new format.
 * @throws IOException if an error occurs.
 */
public static boolean isNewExcelFormat(InputStream inputStream) throws IOException {

    boolean newFormat = false;

    // Ensure that there is at least some data there
    byte[] headers = IOUtils.peekFirst8Bytes(inputStream);

    if (NPOIFSFileSystem.hasPOIFSHeader(headers)) {
        newFormat = false;
    }
    if (POIXMLDocument.hasOOXMLHeader(new ByteArrayInputStream(headers))) {
        newFormat = true;
    }

    return newFormat;

}
 
開發者ID:Talend,項目名稱:data-prep,代碼行數:25,代碼來源:XlsUtils.java

示例9: decompress

import org.apache.poi.util.IOUtils; //導入依賴的package包/類
/**
 * Decompresses the whole of the compressed RTF
 *  stream, outputting the resulting RTF bytes.
 * Note - will decompress any padding at the end of
 *  the input, if present, use {@link #getDeCompressedSize()}
 *  if you need to know how much of the result is
 *  real. (Padding may be up to 7 bytes).
 */
public void decompress(InputStream src, OutputStream res) throws IOException {
   // Validate the header on the front of the RTF
   compressedSize = LittleEndian.readInt(src);
   decompressedSize = LittleEndian.readInt(src);
   int compressionType = LittleEndian.readInt(src);
   int dataCRC = LittleEndian.readInt(src);
   
   // TODO - Handle CRC checking on the output side
   
   // Do we need to do anything?
   if(compressionType == UNCOMPRESSED_SIGNATURE_INT) {
      // Nope, nothing fancy to do
      IOUtils.copy(src, res);
   } else if(compressionType == COMPRESSED_SIGNATURE_INT) {
      // We need to decompress it below
   } else {
      throw new IllegalArgumentException("Invalid compression signature " + compressionType);
   }

   // Have it processed
   super.decompress(src, res);
}
 
開發者ID:rmage,項目名稱:gnvc-ims,代碼行數:31,代碼來源:CompressedRTF.java

示例10: generateLogo

import org.apache.poi.util.IOUtils; //導入依賴的package包/類
public void generateLogo(Sheet sheet, int length, Workbook wb, String basePath, Image image) {
    if (image == null) {
        return;
    }

    try {
        sheet.addMergedRegion(new CellRangeAddress(image.getRowFrom(), (short) image.getRowTo() - 1,
                image.getColFrom(), (short) image.getColTo() - 1));
        String imageFilePath = "d:/app/img";
        InputStream is = new FileInputStream(basePath + imageFilePath);
        byte[] bytes = IOUtils.toByteArray(is);
        int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
        is.close();
        CreationHelper helper = wb.getCreationHelper();
        Drawing drawing = sheet.createDrawingPatriarch();
        ClientAnchor anchor = new XSSFClientAnchor(0, 0, 0, 0,
                image.getColFrom(), image.getRowFrom(), image.getColTo(), image.getRowTo() + 1);
        Picture pict = drawing.createPicture(anchor, pictureIdx);

    } catch (IOException e) {
        e.printStackTrace();
    }
}
 
開發者ID:cgfalcon,項目名稱:fluentexcel,代碼行數:24,代碼來源:XlsxRender.java

示例11: copyToTempFile

import org.apache.poi.util.IOUtils; //導入依賴的package包/類
private File copyToTempFile(InputStream is) throws IOException {
	String partName = packagePart.getPartName().getName();
	partName = partName.substring(partName.lastIndexOf('/')+1);
	final int idx = partName.lastIndexOf('.');
	final String prefix = ((idx == -1) ? partName : partName.substring(0, idx)) + "-";
	final String suffix = (idx == -1 || idx == partName.length()-1) ? "" : partName.substring(idx);

	final File of = TempFile.createTempFile(prefix, suffix);
	try (FileOutputStream fos = new FileOutputStream(of)) {
		IOUtils.copy(is, fos);
	}
	of.deleteOnExit();
	return of;
}
 
開發者ID:kiwiwings,項目名稱:poi-visualizer,代碼行數:15,代碼來源:OPCEntry.java

示例12: copyToTempFile

import org.apache.poi.util.IOUtils; //導入依賴的package包/類
private File copyToTempFile(InputStream is) throws IOException {
	final String partName = entry.getName();
	final int idx = partName.lastIndexOf('.');
	final String prefix = ((idx == -1) ? partName : partName.substring(0, idx)) + "-";
	final String suffix = (idx == -1 || idx == partName.length()-1) ? "" : partName.substring(idx);

	final File of = TempFile.createTempFile(prefix, suffix);
	try (FileOutputStream fos = new FileOutputStream(of)) {
		IOUtils.copy(is, fos);
	}
	of.deleteOnExit();
	return of;
}
 
開發者ID:kiwiwings,項目名稱:poi-visualizer,代碼行數:14,代碼來源:OLEEntry.java

示例13: copyToTempFile

import org.apache.poi.util.IOUtils; //導入依賴的package包/類
private File copyToTempFile(InputStream is) throws IOException {
	final String prefix = "embed-"+embed.getPersistId()+"-";
	final String suffix = ".dat";

	final File of = TempFile.createTempFile(prefix, suffix);
	try (FileOutputStream fos = new FileOutputStream(of)) {
		IOUtils.copy(is, fos);
	}
	of.deleteOnExit();
	return of;
}
 
開發者ID:kiwiwings,項目名稱:poi-visualizer,代碼行數:12,代碼來源:HSLFOleEmbed.java

示例14: copyToTempFile

import org.apache.poi.util.IOUtils; //導入依賴的package包/類
private File copyToTempFile(InputStream is) throws IOException {
	final String prefix = record.getClass().getSimpleName() + "-";
	final String suffix = ".zip";

	final File of = TempFile.createTempFile(prefix, suffix);
	try (FileOutputStream fos = new FileOutputStream(of)) {
		IOUtils.copy(is, fos);
	}
	of.deleteOnExit();
	return of;
}
 
開發者ID:kiwiwings,項目名稱:poi-visualizer,代碼行數:12,代碼來源:HSLFEntry.java

示例15: clearCurrentFile

import org.apache.poi.util.IOUtils; //導入依賴的package包/類
public void clearCurrentFile() {
	Object userObject = treeRoot.getUserObject();
	if (userObject instanceof TreeModelEntry) {
		IOUtils.closeQuietly((TreeModelEntry)userObject);
		treeRoot.setUserObject(null);
	}
	treeRoot.removeAllChildren();
	treeRoot.setUserObject("Not loaded ...");
	treeModel.reload(treeRoot);
}
 
開發者ID:kiwiwings,項目名稱:poi-visualizer,代碼行數:11,代碼來源:POITopMenuBar.java


注:本文中的org.apache.poi.util.IOUtils類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。