Package ole

Source Code of ole.OleFile

package ole;

import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;

import pptViewer.PptException;

/**
* Die zu untersuchende Binärdatei
* @author Michael Roth <michi.ro@gmx.de>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.
*
*/
public class OleFile {
 
  private RandomAccessFile file = null;
  private Header header;
  private FAT fat;
  private DIF dif;
  private MiniFat miniFat;
  private Directory directory;
  private int MiniSecSize, MiniSecStart;
 
  public static int DIFSECT = 0x0FFFFFFFC;
  public static int FATSECT = 0x0FFFFFFFD;
  public static int ENDOFCHAIN = 0x0FFFFFFFE;
  public static int FREESECT = 0x0FFFFFFFF;
 

  public OleFile(File selectedFile) throws PptException,FileNotFoundException,IOException {
   
    file = new RandomAccessFile(selectedFile, "r");
    this.readHeader();
  }
 
  /**
   * Liest den Header
   * @throws IOException
   * @throws PptException
   */
  private void readHeader() throws IOException,PptException{
    byte[] data = new byte[512];
    this.file.seek(0);
    this.file.read(data);
    this.header = new Header(data);
    this.dif = new DIF(this);
    this.fat = new FAT(this);
    this.miniFat = new MiniFat(this);
    this.directory = new Directory(this);
  }
 
  /**
   * Liefert den Block der Datei zurück
   * @param Block Die Blocknummer
   * @return Der Block
   * @throws PptException
   */
  public byte[] getBlock(int Block) throws PptException {
    //System.out.println("Reading File-block "+Block+" from file");
   
    if (Block == OleFile.ENDOFCHAIN) throw new PptException("EndOfChain");
    if (Block == OleFile.DIFSECT) throw new PptException("DifSector");
    if (Block == OleFile.FATSECT) throw new PptException("FatSector");
    if (Block == OleFile.FREESECT) throw new PptException("FreeSector");
   
    byte[] dataArray = new byte[this.getHeader().getSecSize()];
    try {
      this.file.seek(this.getHeader().getSecSize()*Block+512);
      this.file.read(dataArray);
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
    return dataArray;
  }
 
  public Header getHeader() {
    return this.header;
  }

  public RandomAccessFile getFile() {
    return file;
  }

  public FAT getFat() {
    return fat;
  }

  public DIF getDif() {
    return dif;
  }

  public MiniFat getMiniFat() {
    return miniFat;
  }

  public Directory getDirectory() {
    return directory;
  }

  public int getMiniSecSize() {
    return MiniSecSize;
  }

  public void setMiniSecSize(int miniSecSize) {
    MiniSecSize = miniSecSize;
  }

  public int getMiniSecStart() {
    return MiniSecStart;
  }

  public void setMiniSecStart(int miniSecStart) {
    MiniSecStart = miniSecStart;
  }

}
TOP

Related Classes of ole.OleFile

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.