Java Code Examples for org.apache.poi.poifs.filesystem.DirectoryEntry#hasEntry()

The following examples show how to use org.apache.poi.poifs.filesystem.DirectoryEntry#hasEntry() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PropertySet.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Writes a property set to a document in a POI filesystem directory.
 *
 * @param dir The directory in the POI filesystem to write the document to.
 * @param name The document's name. If there is already a document with the
 * same name in the directory the latter will be overwritten.
 *
 * @throws WritingNotSupportedException if the filesystem doesn't support writing
 * @throws IOException if the old entry can't be deleted or the new entry be written
 */
public void write(final DirectoryEntry dir, final String name)
throws WritingNotSupportedException, IOException {
    /* If there is already an entry with the same name, remove it. */
    if (dir.hasEntry(name)) {
        final Entry e = dir.getEntry(name);
        e.delete();
    }

    /* Create the new entry. */
    dir.createDocument(name, toInputStream());
}
 
Example 2
Source File: DataSpaceMapUtils.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public static DocumentEntry createEncryptionEntry(DirectoryEntry dir, String path, EncryptionRecord out) throws IOException {
    String parts[] = path.split("/");
    for (int i=0; i<parts.length-1; i++) {
        dir = dir.hasEntry(parts[i])
            ? (DirectoryEntry)dir.getEntry(parts[i])
            : dir.createDirectory(parts[i]);
    }
    
    final byte buf[] = new byte[5000];        
    LittleEndianByteArrayOutputStream bos = new LittleEndianByteArrayOutputStream(buf, 0);
    out.write(bos);
    
    String fileName = parts[parts.length-1];
    
    if (dir.hasEntry(fileName)) {
        dir.getEntry(fileName).delete();
    }
    
    return dir.createDocument(fileName, bos.getWriteIndex(), new POIFSWriterListener(){
        public void processPOIFSWriterEvent(POIFSWriterEvent event) {
            try {
                event.getStream().write(buf, 0, event.getLimit());
            } catch (IOException e) {
                throw new EncryptedDocumentException(e);
            }
        }
    });
}
 
Example 3
Source File: MPP14Reader.java    From mpxj with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * This method extracts and collates the value list information
 * for custom column value lists.
 * @throws IOException
 */
private void processCustomValueLists() throws IOException
{
   DirectoryEntry taskDir = (DirectoryEntry) m_projectDir.getEntry("TBkndTask");
   if (taskDir.hasEntry("Props"))
   {
      Props taskProps = new Props14(m_inputStreamFactory.getInstance(taskDir, "Props"));

      CustomFieldValueReader14 reader = new CustomFieldValueReader14(m_file.getProjectProperties(), m_file.getCustomFields(), m_outlineCodeVarMeta, m_outlineCodeVarData, m_outlineCodeFixedData, m_outlineCodeFixedData2, taskProps);
      reader.process();
   }
}