Categories:
Audio (13)
Biotech (29)
Bytecode (36)
Database (77)
Framework (7)
Game (7)
General (507)
Graphics (53)
I/O (35)
IDE (2)
JAR Tools (102)
JavaBeans (21)
JDBC (121)
JDK (426)
JSP (20)
Logging (108)
Mail (58)
Messaging (8)
Network (84)
PDF (97)
Report (7)
Scripting (84)
Security (32)
Server (121)
Servlet (26)
SOAP (24)
Testing (54)
Web (15)
XML (322)
Collections:
Other Resources:
What Is poi-5.2.3.jar?
What Is poi-5.2.3.jar?
✍: FYIcenter.com
poi-5.2.3.jar is one of the JAR files for Apache POI 5.2.3, which
provides an API for Microsoft document files of Word, Excel, PowerPoint, and Visio.
poi-5.2.3.jar supports Apache POI components that read and write Microsoft's OLE 2 Compound document format, which is used in early versions of Microsoft Office tools like Word 97, Excel 97, PowerPoint 97, etc.
poi-5.2.3.jar is distributed as part of the poi-bin-5.2.3-20220909.zip download file.
JAR File Size and Download Location:
JAR name: poi-5.2.3.jar Target JDK version: 9 File name: poi.jar, poi-5.2.3.jar File size: 2964641 bytes Release date: 09-09-2022 Download: Apache POI Website
Here are Java Source Code files for poi-5.2.3.jar:
⏎ org/apache/poi/ss/usermodel/WorkbookFactory.java
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.ss.usermodel;
import static org.apache.poi.extractor.ExtractorFactory.OOXML_PACKAGE;
import static org.apache.poi.poifs.crypt.Decryptor.DEFAULT_POIFS_ENTRY;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
import org.apache.poi.EmptyFileException;
import org.apache.poi.EncryptedDocumentException;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.poifs.filesystem.DirectoryNode;
import org.apache.poi.poifs.filesystem.FileMagic;
import org.apache.poi.poifs.filesystem.POIFSFileSystem;
/**
* Factory for creating the appropriate kind of Workbook
* (be it {@link HSSFWorkbook} or XSSFWorkbook),
* by auto-detecting from the supplied input.
*/
public final class WorkbookFactory {
private static class Singleton {
private static final WorkbookFactory INSTANCE = new WorkbookFactory();
}
private interface ProviderMethod {
Workbook create(WorkbookProvider prov) throws IOException;
}
private final List<WorkbookProvider> provider = new ArrayList<>();
private WorkbookFactory() {
ClassLoader cl = WorkbookFactory.class.getClassLoader();
ServiceLoader.load(WorkbookProvider.class, cl).forEach(provider::add);
}
/**
* Create a new empty Workbook, either XSSF or HSSF depending
* on the parameter
*
* @param xssf If an XSSFWorkbook or a HSSFWorkbook should be created
*
* @return The created workbook
*
* @throws IOException if an error occurs while creating the objects
* @throws RuntimeException a number of other runtime exceptions can be thrown, especially if there are problems with the
* input format
*/
public static Workbook create(boolean xssf) throws IOException {
return wp(xssf ? FileMagic.OOXML : FileMagic.OLE2, WorkbookProvider::create);
}
/**
* Creates a Workbook from the given POIFSFileSystem.
*
* <p>Note that in order to properly release resources the
* Workbook should be closed after use.
*
* @param fs The {@link POIFSFileSystem} to read the document from
*
* @return The created workbook
*
* @throws IOException if an error occurs while reading the data
* @throws RuntimeException a number of runtime exceptions can be thrown, especially if there are problems with the
* input format
*/
public static Workbook create(POIFSFileSystem fs) throws IOException {
return create(fs, null);
}
/**
* Creates a Workbook from the given POIFSFileSystem, which may
* be password protected.
*
* <p>Note that in order to properly release resources the
* Workbook should be closed after use.
*
* @param fs The {@link POIFSFileSystem} to read the document from
* @param password The password that should be used or null if no password is necessary.
*
* @return The created Workbook
*
* @throws IOException if an error occurs while reading the data
* @throws RuntimeException a number of runtime exceptions can be thrown, especially if there are problems with the
* input format
*/
private static Workbook create(final POIFSFileSystem fs, String password) throws IOException {
return create(fs.getRoot(), password);
}
/**
* Creates a Workbook from the given DirectoryNode.
*
* <p>Note that in order to properly release resources the
* Workbook should be closed after use.
*
* @param root The {@link DirectoryNode} to start reading the document from
*
* @return The created Workbook
*
* @throws IOException if an error occurs while reading the data
* @throws RuntimeException a number of other exceptions can be thrown, especially if there are problems with the
* input format
*/
public static Workbook create(final DirectoryNode root) throws IOException {
return create(root, null);
}
/**
* Creates a Workbook from the given DirectoryNode, which may
* be password protected.
*
* <p>Note that in order to properly release resources the
* Workbook should be closed after use.
*
* @param root The {@link DirectoryNode} to start reading the document from
* @param password The password that should be used or null if no password is necessary.
*
* @return The created Workbook
*
* @throws IOException if an error occurs while reading the data
* @throws RuntimeException a number of runtime exceptions can be thrown, especially if there are problems with the
* input format
*/
public static Workbook create(final DirectoryNode root, String password) throws IOException {
// Encrypted OOXML files go inside OLE2 containers, is this one?
if (root.hasEntry(DEFAULT_POIFS_ENTRY) || root.hasEntry(OOXML_PACKAGE)) {
return wp(FileMagic.OOXML, w -> w.create(root, password));
} else {
return wp(FileMagic.OLE2, w -> w.create(root, password));
}
}
/**
* Creates the appropriate HSSFWorkbook / XSSFWorkbook from
* the given InputStream.
*
* <p>Your input stream MUST either support mark/reset, or
* be wrapped as a {@link BufferedInputStream}!
* Note that using an {@link InputStream} has a higher memory footprint
* than using a {@link File}.</p>
*
* <p>Note that in order to properly release resources the
* Workbook should be closed after use. Note also that loading
* from an InputStream requires more memory than loading
* from a File, so prefer {@link #create(File)} where possible.
*
* @param inp The {@link InputStream} to read data from.
*
* @return The created Workbook
*
* @throws IOException if an error occurs while reading the data
* @throws EncryptedDocumentException If the Workbook given is password protected
* @throws EmptyFileException If the given data is empty
* @throws RuntimeException a number of other runtime exceptions can be thrown, especially if there are problems with the
* input format
*/
public static Workbook create(InputStream inp) throws IOException, EncryptedDocumentException {
return create(inp, null);
}
/**
* Creates the appropriate HSSFWorkbook / XSSFWorkbook from
* the given InputStream, which may be password protected.
*
* <p>Your input stream MUST either support mark/reset, or
* be wrapped as a {@link BufferedInputStream}!
* Note that using an {@link InputStream} has a higher memory footprint
* than using a {@link File}.</p>
*
* <p>Note that in order to properly release resources the
* Workbook should be closed after use. Note also that loading
* from an InputStream requires more memory than loading
* from a File, so prefer {@link #create(File)} where possible.</p>
*
* @param inp The {@link InputStream} to read data from.
* @param password The password that should be used or null if no password is necessary.
*
* @return The created Workbook
*
* @throws IOException if an error occurs while reading the data
* @throws EncryptedDocumentException If the wrong password is given for a protected file
* @throws EmptyFileException If the given data is empty
* @throws RuntimeException a number of other runtime exceptions can be thrown, especially if there are problems with the
* input format
*/
public static Workbook create(InputStream inp, String password) throws IOException, EncryptedDocumentException {
InputStream is = FileMagic.prepareToCheckMagic(inp);
byte[] emptyFileCheck = new byte[1];
is.mark(emptyFileCheck.length);
if (is.read(emptyFileCheck) < emptyFileCheck.length) {
throw new EmptyFileException();
}
is.reset();
final FileMagic fm = FileMagic.valueOf(is);
if (FileMagic.OOXML == fm) {
return wp(fm, w -> w.create(is));
}
if (FileMagic.OLE2 != fm) {
throw new IOException("Can't open workbook - unsupported file type: "+fm);
}
POIFSFileSystem poifs = new POIFSFileSystem(is);
DirectoryNode root = poifs.getRoot();
boolean isOOXML = root.hasEntry(DEFAULT_POIFS_ENTRY) || root.hasEntry(OOXML_PACKAGE);
return wp(isOOXML ? FileMagic.OOXML : fm, w -> w.create(root, password));
}
/**
* Creates the appropriate HSSFWorkbook / XSSFWorkbook from
* the given File, which must exist and be readable.
* <p>Note that in order to properly release resources the
* Workbook should be closed after use.
*
* @param file The file to read data from.
*
* @return The created Workbook
*
* @throws IOException if an error occurs while reading the data
* @throws EncryptedDocumentException If the Workbook given is password protected
* @throws EmptyFileException If the given data is empty
* @throws RuntimeException a number of other runtime exceptions can be thrown, especially if there are problems with the
* input format
*/
public static Workbook create(File file) throws IOException, EncryptedDocumentException {
return create(file, null);
}
/**
* Creates the appropriate HSSFWorkbook / XSSFWorkbook from
* the given File, which must exist and be readable, and
* may be password protected
* <p>Note that in order to properly release resources the
* Workbook should be closed after use.
*
* @param file The file to read data from.
* @param password The password that should be used or null if no password is necessary.
*
* @return The created Workbook
*
* @throws IOException if an error occurs while reading the data
* @throws EncryptedDocumentException If the wrong password is given for a protected file
* @throws EmptyFileException If the given data is empty
* @throws RuntimeException a number of other runtime exceptions can be thrown, especially if there are problems with the
* input format
*/
public static Workbook create(File file, String password) throws IOException, EncryptedDocumentException {
return create(file, password, false);
}
/**
* Creates the appropriate HSSFWorkbook / XSSFWorkbook from
* the given File, which must exist and be readable, and
* may be password protected
* <p>Note that in order to properly release resources the
* Workbook should be closed after use.
*
* @param file The file to read data from.
* @param password The password that should be used or null if no password is necessary.
* @param readOnly If the Workbook should be opened in read-only mode to avoid writing back
* changes when the document is closed.
*
* @return The created Workbook
*
* @throws IOException if an error occurs while reading the data
* @throws EncryptedDocumentException If the wrong password is given for a protected file
* @throws EmptyFileException If the given data is empty
* @throws RuntimeException a number of other runtime exceptions can be thrown, especially if there are problems with the
* input format
*/
public static Workbook create(File file, String password, boolean readOnly) throws IOException, EncryptedDocumentException {
if (!file.exists()) {
throw new FileNotFoundException(file.toString());
}
if (file.length() == 0) {
throw new EmptyFileException(file);
}
FileMagic fm = FileMagic.valueOf(file);
if (fm == FileMagic.OOXML) {
return wp(fm, w -> w.create(file, password, readOnly));
} else if (fm == FileMagic.OLE2) {
final boolean ooxmlEnc;
try (POIFSFileSystem fs = new POIFSFileSystem(file, true)) {
DirectoryNode root = fs.getRoot();
ooxmlEnc = root.hasEntry(DEFAULT_POIFS_ENTRY) || root.hasEntry(OOXML_PACKAGE);
}
return wp(ooxmlEnc ? FileMagic.OOXML : fm, w -> w.create(file, password, readOnly));
} else {
throw new IOException("Can't open workbook - unsupported file type: "+fm);
}
}
private static Workbook wp(FileMagic fm, ProviderMethod fun) throws IOException {
for (WorkbookProvider prov : Singleton.INSTANCE.provider) {
if (prov.accepts(fm)) {
return fun.create(prov);
}
}
throw new IOException("Your InputStream was neither an OLE2 stream, nor an OOXML stream " +
"or you haven't provide the poi-ooxml*.jar in the classpath/modulepath - FileMagic: " + fm +
", having providers: " + Singleton.INSTANCE.provider);
}
public static void addProvider(WorkbookProvider provider){
Singleton.INSTANCE.provider.add(provider);
}
public static void removeProvider(Class<? extends WorkbookProvider> provider){
Singleton.INSTANCE.provider.removeIf(p -> p.getClass().isAssignableFrom(provider));
}
}
⏎ org/apache/poi/ss/usermodel/WorkbookFactory.java
Or download all of them as a single archive file:
File name: poi-5.2.3-src.zip File size: 2479830 bytes Release date: 2022-09-09 Download
⇒ What Is poi-ooxml-5.2.3.jar?
⇐ What Is poi-bin-5.2.3-20220909.zip?
2017-04-04, ≈377🔥, 0💬
Popular Posts:
What Is commons-logging-1.2.jar? commons-logging-1.2.jar is the JAR file for Apache Commons Logging ...
What Is ojdbc5.jar for Oracle 11g R1? ojdbc5.jar for Oracle 11g R1 is the JAR files of ojdbc.jar, JD...
HttpComponents Core Source Code Files are provided in the source package file, httpcomponents-core-5...
Jackson is "the Java JSON library" or "the best JSON parser for Java". Or simply as "JSON for Java"....
What Is js.jar in Rhino JavaScript 1.7R5? js.jar in Rhino JavaScript 1.7R5 is the JAR file for Rhino...