Methods Summary |
---|
public static void | copy(java.io.InputStream in, java.io.OutputStream out)Reads bytes from an input stream and writes them to an
output stream until end of file is encountered.
final int BUF_SIZE = 1000;
byte[] b = new byte[BUF_SIZE];
int read;
boolean eof = false;
while (!eof)
{
try
{
read = in.read(b, 0, BUF_SIZE);
if (read > 0)
out.write(b, 0, read);
else
eof = true;
}
catch (EOFException ex)
{
eof = true;
}
}
|
public static void | printSystemProperties()Prints the system properties to System.out.
final Properties p = System.getProperties();
final List names = new LinkedList();
for (Iterator i = p.keySet().iterator(); i.hasNext();)
names.add(i.next());
Collections.sort(names);
for (final Iterator i = names.iterator(); i.hasNext();)
{
String name = (String) i.next();
String value = (String) p.get(name);
System.out.println(name + ": " + value);
}
System.out.println("Current directory: " +
System.getProperty("user.dir"));
|
public static POIFile[] | readPOIFiles(java.io.File poiFs)Reads all files from a POI filesystem and returns them as an
array of {@link POIFile} instances. This method loads all files
into memory and thus does not cope well with large POI
filessystems.
return readPOIFiles(poiFs, null);
|
public static POIFile[] | readPOIFiles(java.io.File poiFs, java.lang.String[] poiFiles)Reads a set of files from a POI filesystem and returns them
as an array of {@link POIFile} instances. This method loads all
files into memory and thus does not cope well with large POI
filessystems.
final List files = new ArrayList();
POIFSReader r = new POIFSReader();
POIFSReaderListener pfl = new POIFSReaderListener()
{
public void processPOIFSReaderEvent(final POIFSReaderEvent event)
{
try
{
final POIFile f = new POIFile();
f.setName(event.getName());
f.setPath(event.getPath());
final InputStream in = event.getStream();
final ByteArrayOutputStream out =
new ByteArrayOutputStream();
Util.copy(in, out);
out.close();
f.setBytes(out.toByteArray());
files.add(f);
}
catch (IOException ex)
{
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
};
if (poiFiles == null)
/* Register the listener for all POI files. */
r.registerListener(pfl);
else
/* Register the listener for the specified POI files
* only. */
for (int i = 0; i < poiFiles.length; i++)
r.registerListener(pfl, poiFiles[i]);
/* Read the POI filesystem. */
r.read(new FileInputStream(poiFs));
POIFile[] result = new POIFile[files.size()];
for (int i = 0; i < result.length; i++)
result[i] = (POIFile) files.get(i);
return result;
|
public static POIFile[] | readPropertySets(java.io.File poiFs)Read all files from a POI filesystem which are property set streams
and returns them as an array of {@link org.apache.poi.hpsf.PropertySet}
instances.
final List files = new ArrayList(7);
final POIFSReader r = new POIFSReader();
POIFSReaderListener pfl = new POIFSReaderListener()
{
public void processPOIFSReaderEvent(final POIFSReaderEvent event)
{
try
{
final POIFile f = new POIFile();
f.setName(event.getName());
f.setPath(event.getPath());
final InputStream in = event.getStream();
if (PropertySet.isPropertySetStream(in))
{
final ByteArrayOutputStream out =
new ByteArrayOutputStream();
Util.copy(in, out);
out.close();
f.setBytes(out.toByteArray());
files.add(f);
}
}
catch (Exception ex)
{
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
};
/* Register the listener for all POI files. */
r.registerListener(pfl);
/* Read the POI filesystem. */
r.read(new FileInputStream(poiFs));
POIFile[] result = new POIFile[files.size()];
for (int i = 0; i < result.length; i++)
result[i] = (POIFile) files.get(i);
return result;
|