本文整理匯總了Java中org.apache.poi.util.IOUtils.toByteArray方法的典型用法代碼示例。如果您正苦於以下問題:Java IOUtils.toByteArray方法的具體用法?Java IOUtils.toByteArray怎麽用?Java IOUtils.toByteArray使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.poi.util.IOUtils
的用法示例。
在下文中一共展示了IOUtils.toByteArray方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: 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;
}
示例2: 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();
}
}
示例3: fetchBrandingPackage
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
public void fetchBrandingPackage() throws IOException {
InputStream in = null;
try {
FacesContext fc = getFacesContext();
in = fc.getExternalContext().getResourceAsStream(
"/WEB-INF/branding-package.zip");
if (in == null) {
addMessage(null, FacesMessage.SEVERITY_ERROR,
ERROR_FETCH_BRANDING_PACKAGE);
logger.logError(LogMessageIdentifier.ERROR_FETCH_BRANDING_PACKAGE_RETURN_NULL);
return;
}
byte[] bytes = IOUtils.toByteArray(in);
brandingPackage = bytes;
if (brandingPackage == null) {
addMessage(null, FacesMessage.SEVERITY_ERROR,
ERROR_FETCH_BRANDING_PACKAGE);
logger.logError(LogMessageIdentifier.ERROR_FETCH_BRANDING_PACKAGE_RETURN_NULL);
return;
}
} finally {
if (in != null) {
in.close();
}
}
}
示例4: testXlsInputStream
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
/**
* Following test loads a 400KB xls file using both an XlsInputStream and into a byte array,
* then assesses the XlsInputStream is returning the correct data.
*/
@Test
public void testXlsInputStream() throws Exception {
final String filePath = TestTools.getWorkingPath() + "/src/test/resources/excel/poi44891.xls";
final byte[] bytes = IOUtils.toByteArray(new FileInputStream(filePath));
final XlsInputStream xlsStream = new XlsInputStream(bufferManager, new ByteArrayInputStream(bytes));
final ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
final int bufferSize = 500;
final byte[] buf1 = new byte[bufferSize];
final byte[] buf2 = new byte[bufferSize];
int offset = 0;
while (offset < bytes.length) {
int r1 = bis.read(buf1);
int r2 = xlsStream.read(buf2);
Assert.assertEquals(String.format("Error after reading %d bytes", offset), r1, r2);
final String errorMsg = String.format("Error after reading %d bytes%n" +
"expected: %s%n" +
"was: %s%n", offset, Arrays.toString(buf1), Arrays.toString(buf2));
Assert.assertTrue(errorMsg, Arrays.equals(buf1, buf2));
offset += bufferSize;
}
}
示例5: readStream
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
/**
* Read stream.
*
* @param inStream
* the in stream
* @return the byte[]
*/
public static byte[] readStream(final InputStream inStream) {
try {
return IOUtils.toByteArray(inStream);
} catch (IOException e) {
throw new JKException(e);
}
//
// try {
// DataInputStream in = null;
// try {
// in = new DataInputStream(inStream);
// int ch;
//
// List<Byte> bytes=new ArrayList<>();
// while((ch=in.read())!=-1){
// bytes.add(ch);
// }
// return arr;
// } finally {
// if (in != null) {
// in.close();
// }
// }
// } catch (final IOException e) {
// throw new RuntimeException(e);
// }
}
示例6: imageTo
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
/**
* Stream 을 MIME (HTML기반) 이미지로 교체함.
*
* @작성자 : KYJ
* @작성일 : 2016. 5. 31.
* @param is
* @return
* @throws IOException
*/
public static String imageTo(InputStream is) throws IOException {
byte[] byteArray = IOUtils.toByteArray(is);
StringBuilder b = new StringBuilder();
// BASE64로 컨버팅.
byteArray = Base64.getMimeEncoder().encode(byteArray);
b.append(new String("<img src=\"data:image/jpg;base64,"));
b.append(new String(byteArray));
b.append(new String("\" alt=\"\" width=\"683\" height=\"420\" />"));
return b.toString();
}
示例7: getConFromNotification
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
/**
* store "con" value to database when server is received notification
*
* @param request
* @param model
* @return
* @throws Exception
*/
@ResponseBody
@RequestMapping(value = "/{system}/onem2m/noti")
public String getConFromNotification(HttpServletRequest request, ModelMap model) {
String result = null;
try(InputStream is = request.getInputStream()){
byte[] buffer = IOUtils.toByteArray(is);
String xml = new String(buffer);
HashMap<String, String> notification = new HashMap<String, String>();
notification.put("con", Util.getValueFromXml(xml, "con"));
notification.put("cnf", Util.getValueFromXml(xml, "cnf"));
notification.put("sur", Util.getValueFromXml(xml, "sur"));
Util.getInstance().printMap(notification);
boolean isSuccess = hdmDAO.insertNotificationResource(notification);
if( isSuccess ){
} else {
}
} catch(Exception e) {
e.printStackTrace();
} finally {
}
return result;
}
示例8: fileData
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
private static byte[] fileData(String filePath) throws IOException {
File file = new File(filePath);//存放照片的文件
InputStream fis = null;
byte[] imageByteArray = null;
fis = new FileInputStream(file);
imageByteArray= IOUtils.toByteArray(fis);
return imageByteArray;
}
示例9: toByteArray
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
/**
* 流轉換成byte數組
*
* @param is
* @return
*/
public static byte[] toByteArray(InputStream is) {
try {
return IOUtils.toByteArray(is);
} catch (IOException e) {
logger.error("toByteArray error", e);
}
return null;
}
示例10: getImageData
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
public static byte[] getImageData(String imgPath){
byte[] arrayByte = null;
try {
Bundle buddle = Platform.getBundle(Activator.PLUGIN_ID);
URL defaultUrl = buddle.getEntry(imgPath);
String imagePath = imgPath;
imagePath = FileLocator.toFileURL(defaultUrl).getPath();
arrayByte = IOUtils.toByteArray(new FileInputStream(new File(imagePath)));
} catch (Exception e) {
}
return arrayByte;
}
示例11: main
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
public static void main(String[] args) throws Exception
{
String dataPath = "src/featurescomparison/workingwithworkbook/addimages/data/";
//create a new workbook
Workbook wb = new XSSFWorkbook(); //or new HSSFWorkbook();
//add picture data to this workbook.
InputStream is = new FileInputStream(dataPath + "aspose.jpg");
byte[] bytes = IOUtils.toByteArray(is);
int pictureIdx = wb.addPicture(bytes, Workbook.PICTURE_TYPE_JPEG);
is.close();
CreationHelper helper = wb.getCreationHelper();
//create sheet
Sheet sheet = wb.createSheet();
// Create the drawing patriarch. This is the top level container for all shapes.
Drawing drawing = sheet.createDrawingPatriarch();
//add a picture shape
ClientAnchor anchor = helper.createClientAnchor();
//set top-left corner of the picture,
//subsequent call of Picture#resize() will operate relative to it
anchor.setCol1(3);
anchor.setRow1(2);
Picture pict = drawing.createPicture(anchor, pictureIdx);
//auto-size picture relative to its top-left corner
pict.resize();
//save workbook
String file = dataPath + "ApacheImage.xls";
if(wb instanceof XSSFWorkbook) file += "x";
FileOutputStream fileOut = new FileOutputStream(file);
wb.write(fileOut);
fileOut.close();
System.out.println("Done...");
}
示例12: readValue
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
public void readValue(InputStream value) throws IOException {
// Stored in the file as us-ascii
try {
byte[] data = IOUtils.toByteArray(value);
rawId = new String(data, "ASCII");
} catch(UnsupportedEncodingException e) {
throw new RuntimeException("Core encoding not found, JVM broken?", e);
}
// Now process the date
String[] parts = rawId.split(";");
for(String part : parts) {
if(part.startsWith("l=")) {
// Format of this bit appears to be l=<id>-<time>-<number>
if(part.indexOf('-') != -1 &&
part.indexOf('-') != part.lastIndexOf('-')) {
String dateS = part.substring(part.indexOf('-')+1, part.lastIndexOf('-'));
// Should be yymmddhhmmssZ
Matcher m = datePatern.matcher(dateS);
if(m.matches()) {
date = Calendar.getInstance();
date.set(Calendar.YEAR, Integer.parseInt(m.group(1)) + 2000);
date.set(Calendar.MONTH, Integer.parseInt(m.group(2)) - 1); // Java is 0 based
date.set(Calendar.DATE, Integer.parseInt(m.group(3)));
date.set(Calendar.HOUR_OF_DAY, Integer.parseInt(m.group(4)));
date.set(Calendar.MINUTE, Integer.parseInt(m.group(5)));
date.set(Calendar.SECOND, Integer.parseInt(m.group(6)));
date.set(Calendar.MILLISECOND, 0);
} else {
logger.log(POILogger.WARN, "Warning - unable to make sense of date " + dateS);
}
}
}
}
}
示例13: readValue
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
public void readValue(InputStream value) throws IOException {
this.value = IOUtils.toByteArray(value);
}
示例14: readValue
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
public void readValue(InputStream value) throws IOException {
rawValue = IOUtils.toByteArray(value);
parseString();
}
示例15: convertFileToBytes
import org.apache.poi.util.IOUtils; //導入方法依賴的package包/類
/**
* Metodo di utility, apre un file e lo converte in un array di Byte.<br>
* L'array di byte � utilizzato da POI per inserire le immagini nel workBook
* @param fileName path/nome del file da convertire
* @return 'versione binaria' del file
* @throws IOException Lancia IOException se il file non esiste o ci sono altri problemi in lettura/scrittura
*/
protected static byte[] convertFileToBytes(InputStream image_asStream) throws IOException
{
byte [] array = IOUtils.toByteArray(image_asStream);
image_asStream.close();
return array;
}