whitespace
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1711906 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
87ad007ce4
commit
3753893f1a
@ -37,53 +37,51 @@ import org.apache.poi.xssf.usermodel.XSSFWorkbook;
|
|||||||
* @author Josh Micich
|
* @author Josh Micich
|
||||||
*/
|
*/
|
||||||
public class XSSFTestDataSamples {
|
public class XSSFTestDataSamples {
|
||||||
/**
|
/**
|
||||||
* Used by {@link writeOutAndReadBack(R wb, String testName)}. If a
|
* Used by {@link writeOutAndReadBack(R wb, String testName)}. If a
|
||||||
* value is set for this in the System Properties, the xlsx file
|
* value is set for this in the System Properties, the xlsx file
|
||||||
* will be written out to that directory.
|
* will be written out to that directory.
|
||||||
*/
|
*/
|
||||||
public static final String TEST_OUTPUT_DIR = "poi.test.xssf.output.dir";
|
public static final String TEST_OUTPUT_DIR = "poi.test.xssf.output.dir";
|
||||||
|
|
||||||
public static File getSampleFile(String sampleFileName) {
|
public static File getSampleFile(String sampleFileName) {
|
||||||
return HSSFTestDataSamples.getSampleFile(sampleFileName);
|
return HSSFTestDataSamples.getSampleFile(sampleFileName);
|
||||||
}
|
}
|
||||||
public static OPCPackage openSamplePackage(String sampleName) {
|
public static OPCPackage openSamplePackage(String sampleName) {
|
||||||
try {
|
try {
|
||||||
return OPCPackage.open(
|
return OPCPackage.open(HSSFTestDataSamples.openSampleFileStream(sampleName));
|
||||||
HSSFTestDataSamples.openSampleFileStream(sampleName)
|
} catch (Exception e) {
|
||||||
);
|
throw new RuntimeException(e);
|
||||||
} catch(Exception e) {
|
}
|
||||||
throw new RuntimeException(e);
|
}
|
||||||
}
|
public static XSSFWorkbook openSampleWorkbook(String sampleName) {
|
||||||
}
|
InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleName);
|
||||||
public static XSSFWorkbook openSampleWorkbook(String sampleName) {
|
try {
|
||||||
InputStream is = HSSFTestDataSamples.openSampleFileStream(sampleName);
|
return new XSSFWorkbook(is);
|
||||||
try {
|
} catch (IOException e) {
|
||||||
return new XSSFWorkbook(is);
|
throw new RuntimeException(e);
|
||||||
} catch (IOException e) {
|
}
|
||||||
throw new RuntimeException(e);
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
public static <R extends Workbook> R writeOutAndReadBack(R wb) {
|
public static <R extends Workbook> R writeOutAndReadBack(R wb) {
|
||||||
Workbook result;
|
Workbook result;
|
||||||
try {
|
try {
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream(8192);
|
ByteArrayOutputStream baos = new ByteArrayOutputStream(8192);
|
||||||
wb.write(baos);
|
wb.write(baos);
|
||||||
InputStream is = new ByteArrayInputStream(baos.toByteArray());
|
InputStream is = new ByteArrayInputStream(baos.toByteArray());
|
||||||
if (wb instanceof HSSFWorkbook) {
|
if (wb instanceof HSSFWorkbook) {
|
||||||
result = new HSSFWorkbook(is);
|
result = new HSSFWorkbook(is);
|
||||||
} else if (wb instanceof XSSFWorkbook) {
|
} else if (wb instanceof XSSFWorkbook) {
|
||||||
result = new XSSFWorkbook(is);
|
result = new XSSFWorkbook(is);
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException("Unexpected workbook type ("
|
throw new RuntimeException("Unexpected workbook type ("
|
||||||
+ wb.getClass().getName() + ")");
|
+ wb.getClass().getName() + ")");
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
R r = (R) result;
|
R r = (R) result;
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user