Class Converter
java.lang.Object
io.github.mbenincasa.javaexcelutils.tools.Converter
Converter is the static class with implementations of conversion methods- Since:
- 0.2.0
- Author:
- Mirko Benincasa
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]csvToExcelByte(byte[] bytes, String sheetName, Extension extension) static FilecsvToExcelFile(File fileInput, String sheetName, String pathname, Extension extension) static ByteArrayOutputStreamcsvToExcelStream(InputStream inputStream, String sheetName, Extension extension) excelByteToObjects(byte[] bytes, List<ExcelToObject<?>> excelToObjects) excelFileToObjects(File file, List<ExcelToObject<?>> excelToObjects) excelStreamToObjects(InputStream inputStream, List<ExcelToObject<?>> excelToObjects) excelToCsvByte(byte[] bytes) excelToCsvFile(File excelFile, String path) static Map<String,ByteArrayOutputStream> excelToCsvStream(InputStream excelInputStream) static byte[]excelToJsonByte(byte[] bytes) static FileexcelToJsonFile(File excelFile, String pathname) static ByteArrayOutputStreamexcelToJsonStream(InputStream excelInputStream) static <T> byte[]jsonToExcelByte(byte[] bytes, JsonToExcel<T> jsonToExcel, Extension extension, Boolean writeHeader) static <T> FilejsonToExcelFile(File jsonFile, JsonToExcel<T> jsonToExcel, Extension extension, String filename, Boolean writeHeader) static <T> ByteArrayOutputStreamjsonToExcelStream(InputStream jsonStream, JsonToExcel<T> jsonToExcel, Extension extension, Boolean writeHeader) static byte[]objectsToExcelByte(List<ObjectToExcel<?>> objectToExcels, Extension extension, Boolean writeHeader) static FileobjectsToExcelFile(List<ObjectToExcel<?>> objectToExcels, Extension extension, String filename, Boolean writeHeader) static ByteArrayOutputStreamobjectsToExcelStream(List<ObjectToExcel<?>> objectToExcels, Extension extension, Boolean writeHeader)
-
Constructor Details
-
Converter
public Converter()
-
-
Method Details
-
objectsToExcelFile
public static File objectsToExcelFile(List<ObjectToExcel<?>> objectToExcels, Extension extension, String filename, Boolean writeHeader) throws ExtensionNotValidException, IOException, FileAlreadyExistsException, SheetAlreadyExistsException - Parameters:
objectToExcels- A list ofObjectToExcels. Each element represents a Sheetextension- The extension to assign to the Excel filefilename- The name, including the path, to be associated with the File.Note: Do not add the extension
writeHeader- Iftrueit will write the header to the first line- Returns:
- The Excel file generated by the conversion
- Throws:
ExtensionNotValidException- If the input file extension does not belong to an Excel fileIOException- If an I/O error has occurredFileAlreadyExistsException- If the destination file already existsSheetAlreadyExistsException- If you try to insert a Sheet that already exists- Since:
- 0.4.0
-
objectsToExcelByte
public static byte[] objectsToExcelByte(List<ObjectToExcel<?>> objectToExcels, Extension extension, Boolean writeHeader) throws ExtensionNotValidException, IOException, SheetAlreadyExistsException - Parameters:
objectToExcels- A list ofObjectToExcels. Each element represents a Sheetextension- The extension to assign to the Excel filewriteHeader- Iftrueit will write the header to the first line- Returns:
- The Excel OutputStream generated by the conversion in the form of a byte array
- Throws:
ExtensionNotValidException- If the input file extension does not belong to an Excel fileIOException- If an I/O error has occurredSheetAlreadyExistsException- If you try to insert a Sheet that already exists- Since:
- 0.4.0
-
objectsToExcelStream
public static ByteArrayOutputStream objectsToExcelStream(List<ObjectToExcel<?>> objectToExcels, Extension extension, Boolean writeHeader) throws ExtensionNotValidException, IOException, SheetAlreadyExistsException - Parameters:
objectToExcels- A list ofObjectToExcels. Each element represents a Sheetextension- The extension to assign to the Excel filewriteHeader- Iftrueit will write the header to the first line- Returns:
- The Excel OutputStream generated by the conversion in the form of a ByteArrayOutputStream
- Throws:
ExtensionNotValidException- If the input file extension does not belong to an Excel fileIOException- If an I/O error has occurredSheetAlreadyExistsException- If you try to insert a Sheet that already exists- Since:
- 0.4.0
-
excelByteToObjects
public static Map<String,java.util.stream.Stream<?>> excelByteToObjects(byte[] bytes, List<ExcelToObject<?>> excelToObjects) throws OpenWorkbookException, SheetNotFoundException, ReadValueException, HeaderNotPresentException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, IOException - Parameters:
bytes- The byte array of the Excel fileexcelToObjects- A list ofExcelToObject. Each element represents a Sheet- Returns:
- A map where the key represents the name of the Sheet and the value the Stream of objects present in the sheet
- Throws:
OpenWorkbookException- If an error occurred while opening the workbookSheetNotFoundException- If the sheet to open is not foundReadValueException- If an error occurs while reading a cellHeaderNotPresentException- If the first row is empty and does not contain the headerInvocationTargetException- If an error occurs while instantiating a new object or setting a fieldNoSuchMethodException- If the setting method or empty constructor of the object is not foundInstantiationException- f an error occurs while instantiating a new objectIllegalAccessException- If a field or fields of theclazzcould not be accessedIOException- If an I/O error occurs- Since:
- 0.4.0
-
excelFileToObjects
public static Map<String,java.util.stream.Stream<?>> excelFileToObjects(File file, List<ExcelToObject<?>> excelToObjects) throws IOException, OpenWorkbookException, SheetNotFoundException, ReadValueException, HeaderNotPresentException, InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException, ExtensionNotValidException - Parameters:
file- The Excel fileexcelToObjects- A list ofExcelToObject. Each element represents a Sheet- Returns:
- A map where the key represents the name of the Sheet and the value the Stream of objects present in the sheet
- Throws:
IOException- If an I/O error occursOpenWorkbookException- If an error occurred while opening the workbookSheetNotFoundException- If the sheet to open is not foundReadValueException- If an error occurs while reading a cellHeaderNotPresentException- If the first row is empty and does not contain the headerInvocationTargetException- If an error occurs while instantiating a new object or setting a fieldNoSuchMethodException- If the setting method or empty constructor of the object is not foundInstantiationException- If an error occurs while instantiating a new objectIllegalAccessException- If a field or fields of theclazzcould not be accessedExtensionNotValidException- If the input file extension does not belong to an Excel file- Since:
- 0.4.0
-
excelStreamToObjects
public static Map<String,java.util.stream.Stream<?>> excelStreamToObjects(InputStream inputStream, List<ExcelToObject<?>> excelToObjects) throws OpenWorkbookException, SheetNotFoundException, HeaderNotPresentException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, ReadValueException, IOException - Parameters:
inputStream- The InputStream of the Excel fileexcelToObjects- A list ofExcelToObject. Each element represents a Sheet- Returns:
- A map where the key represents the name of the Sheet and the value the Stream of objects present in the sheet
- Throws:
OpenWorkbookException- If an error occurred while opening the workbookSheetNotFoundException- If the sheet to open is not foundHeaderNotPresentException- If the first row is empty and does not contain the headerNoSuchMethodException- If the setting method or empty constructor of the object is not foundInvocationTargetException- If an error occurs while instantiating a new object or setting a fieldInstantiationException- f an error occurs while instantiating a new objectIllegalAccessException- If a field or fields of theclazzcould not be accessedReadValueException- If an error occurs while reading a cellIOException- If an I/O error occurs- Since:
- 0.4.0
-
excelToCsvByte
public static Map<String,byte[]> excelToCsvByte(byte[] bytes) throws OpenWorkbookException, IOException - Parameters:
bytes- The Excel file in the form of a byte array- Returns:
- A map where the key represents the Sheet name and the value is a CSV file for each Sheet
- Throws:
OpenWorkbookException- If an error occurred while opening the workbookIOException- If an I/O error has occurred- Since:
- 0.4.0
-
excelToCsvFile
public static Map<String,File> excelToCsvFile(File excelFile, String path) throws IOException, OpenWorkbookException, ExtensionNotValidException - Parameters:
excelFile- The Excel filepath- The path, without file name, where the files will be saved- Returns:
- A map where the key represents the Sheet name and the value is a CSV file for each Sheet
- Throws:
IOException- If an I/O error has occurredOpenWorkbookException- If an error occurred while opening the workbookExtensionNotValidException- If an extension is not correct- Since:
- 0.4.0
-
excelToCsvStream
public static Map<String,ByteArrayOutputStream> excelToCsvStream(InputStream excelInputStream) throws OpenWorkbookException, IOException - Parameters:
excelInputStream- The Excel file in the form of an InputStream- Returns:
- A map where the key represents the Sheet name and the value is a CSV file for each Sheet
- Throws:
OpenWorkbookException- If an error occurred while opening the workbookIOException- If an I/O error has occurred- Since:
- 0.4.0
-
csvToExcelByte
public static byte[] csvToExcelByte(byte[] bytes, String sheetName, Extension extension) throws com.opencsv.exceptions.CsvValidationException, ExtensionNotValidException, IOException, SheetAlreadyExistsException - Parameters:
bytes- The CSV file in the form of a byte arraysheetName- The name of the sheet to createextension- The extension of the output file. Select an extension withtypeEXCEL- Returns:
- The Excel file in the form of a byte array
- Throws:
com.opencsv.exceptions.CsvValidationException- If the CSV file has invalid formattingExtensionNotValidException- If an extension is not correctIOException- If an I/O error has occurredSheetAlreadyExistsException- If you try to insert a Sheet that already exists- Since:
- 0.4.0
-
csvToExcelFile
public static File csvToExcelFile(File fileInput, String sheetName, String pathname, Extension extension) throws IOException, com.opencsv.exceptions.CsvValidationException, ExtensionNotValidException, SheetAlreadyExistsException - Parameters:
fileInput- The CSV filesheetName- The name of the sheet to createpathname- The path with the file name. Note: Do not add the extensionextension- The extension of the output file. Select an extension withtypeEXCEL- Returns:
- The Excel file
- Throws:
IOException- If an I/O error has occurredcom.opencsv.exceptions.CsvValidationException- If the CSV file has invalid formattingExtensionNotValidException- If an extension is not correctSheetAlreadyExistsException- If you try to insert a Sheet that already exists- Since:
- 0.4.0
-
csvToExcelStream
public static ByteArrayOutputStream csvToExcelStream(InputStream inputStream, String sheetName, Extension extension) throws ExtensionNotValidException, com.opencsv.exceptions.CsvValidationException, IOException, SheetAlreadyExistsException - Parameters:
inputStream- The CSV file in the form of a InputStreamsheetName- The name of the sheet to createextension- The extension of the output file. Select an extension withtypeEXCEL- Returns:
- The Excel file in the form of a ByteArrayOutputStream
- Throws:
ExtensionNotValidException- If an extension is not correctcom.opencsv.exceptions.CsvValidationException- If the CSV file has invalid formattingIOException- If an I/O error has occurredSheetAlreadyExistsException- If you try to insert a Sheet that already exists- Since:
- 0.4.0
-
excelToJsonByte
- Parameters:
bytes- The Excel file in the form of a byte array- Returns:
- The Json file in the form of a byte array
- Throws:
OpenWorkbookException- If an error occurred while opening the workbookIOException- If an I/O error has occurred- Since:
- 0.4.0
-
excelToJsonFile
public static File excelToJsonFile(File excelFile, String pathname) throws IOException, OpenWorkbookException, ExtensionNotValidException - Parameters:
excelFile- The Excel filepathname- The path with the file name. Note: Do not add the extension- Returns:
- The Json file
- Throws:
IOException- If an I/O error has occurredOpenWorkbookException- If an error occurred while opening the workbookExtensionNotValidException- If the extension is incorrect- Since:
- 0.4.0
-
excelToJsonStream
public static ByteArrayOutputStream excelToJsonStream(InputStream excelInputStream) throws OpenWorkbookException, IOException - Parameters:
excelInputStream- The Excel file in the form of an InputStream- Returns:
- The Json file in the form of a ByteArrayOutputStream
- Throws:
OpenWorkbookException- If an error occurred while opening the workbookIOException- If an I/O error has occurred- Since:
- 0.4.0
-
jsonToExcelByte
public static <T> byte[] jsonToExcelByte(byte[] bytes, JsonToExcel<T> jsonToExcel, Extension extension, Boolean writeHeader) throws ExtensionNotValidException, IOException, SheetAlreadyExistsException - Type Parameters:
T- The class parameter of the object- Parameters:
bytes- The Json file in the form of a byte array. Note: Must be formatted as an array of objectsjsonToExcel- It is used to convert Json elements into objectsextension- The extension of the output file. Select an extension withtypeEXCELwriteHeader- Iftrueit will write the header to the first line- Returns:
- The Excel file in the form of a byte array
- Throws:
ExtensionNotValidException- If the extension is incorrectIOException- If an I/O error has occurredSheetAlreadyExistsException- If you try to insert a Sheet that already exists- Since:
- 0.4.0
-
jsonToExcelFile
public static <T> File jsonToExcelFile(File jsonFile, JsonToExcel<T> jsonToExcel, Extension extension, String filename, Boolean writeHeader) throws IOException, ExtensionNotValidException, FileAlreadyExistsException, SheetAlreadyExistsException - Type Parameters:
T- The class parameter of the object- Parameters:
jsonFile- The Json file. Note: Must be formatted as an array of objectsjsonToExcel- It is used to convert Json elements into objectsextension- The extension of the output file. Select an extension withtypeEXCELfilename- File name, including path, to specify where to save. Note: Do not add the extensionwriteHeader- Iftrueit will write the header to the first line- Returns:
- The Excel file
- Throws:
IOException- If an I/O error has occurredExtensionNotValidException- If the extension is incorrectFileAlreadyExistsException- If the destination file already existsSheetAlreadyExistsException- If you try to insert a Sheet that already exists- Since:
- 0.4.0
-
jsonToExcelStream
public static <T> ByteArrayOutputStream jsonToExcelStream(InputStream jsonStream, JsonToExcel<T> jsonToExcel, Extension extension, Boolean writeHeader) throws ExtensionNotValidException, IOException, SheetAlreadyExistsException - Type Parameters:
T- The class parameter of the object- Parameters:
jsonStream- The Json file in the form of an InputStream. Note: Must be formatted as an array of objectsjsonToExcel- It is used to convert Json elements into objectsextension- The extension of the output file. Select an extension withtypeEXCELwriteHeader- Iftrueit will write the header to the first line- Returns:
- The Excel file in the form of a ByteArrayOutputStream
- Throws:
ExtensionNotValidException- If the extension is incorrectIOException- If an I/O error has occurredSheetAlreadyExistsException- If you try to insert a Sheet that already exists- Since:
- 0.4.0
-