com.aspose.words
Class FileFormatUtil

java.lang.Object
    extended by com.aspose.words.FileFormatUtil

public abstract class FileFormatUtil 
extends java.lang.Object

Provides utility methods for working with file formats, such as detecting file format or converting file extensions to/from file format enums.

Method Summary
static intcontentTypeToLoadFormat(java.lang.String contentType)
           Converts IANA content type into a load format enumerated value.
static intcontentTypeToSaveFormat(java.lang.String contentType)
           Converts IANA content type into a save format enumerated value.
static FileFormatInfodetectFileFormat(java.io.InputStream stream)
           Detects and returns the information about a format of a document stored in a stream.
static FileFormatInfodetectFileFormat(java.lang.String fileName)
           Detects and returns the information about a format of a document stored in a disk file.
static intextensionToSaveFormat(java.lang.String extension)
           Converts a file name extension into a SaveFormat value.
static java.lang.StringimageTypeToExtension(int imageType)
           Converts an Aspose.Words image type enumerated value into a file extension. The returned extension is a lower-case string with a leading dot.
static java.lang.StringloadFormatToExtension(int loadFormat)
           Converts a load format enumerated value into a file extension. The returned extension is a lower-case string with a leading dot.
static intloadFormatToSaveFormat(int loadFormat)
           Converts a LoadFormat value to a SaveFormat value if possible.
static java.lang.StringsaveFormatToExtension(int saveFormat)
           Converts a save format enumerated value into a file extension. The returned extension is a lower-case string with a leading dot.
static intsaveFormatToLoadFormat(int saveFormat)
           Converts a SaveFormat value to a LoadFormat value if possible.
 

Method Detail

contentTypeToLoadFormat

public static int contentTypeToLoadFormat(java.lang.String contentType)
Converts IANA content type into a load format enumerated value.

contentTypeToSaveFormat

public static int contentTypeToSaveFormat(java.lang.String contentType)
Converts IANA content type into a save format enumerated value.

detectFileFormat

public static FileFormatInfo detectFileFormat(java.io.InputStream stream)
                                           throws java.lang.Exception
Detects and returns the information about a format of a document stored in a stream.

The stream must be positioned at the beginning of the document.

Detecting a file format might require seeking to various positions in the stream. Because java.io.InputStream is not seekable, this method loads the whole stream into memory temporarily. When this method returns, the stream is positioned at the end of the document.

Even if this method detects the document format, it does not guarantee that the specified document is valid. This method only detects the document format by reading data that is sufficient for detection. To fully verify that a document is valid you need to load the document into a Document object.

This method throws FileCorruptedException when the format is recognized, but the detection cannot complete because of corruption.

Parameters:
stream - The stream.
Returns:
A FileFormatInfo object that contains the detected information.

detectFileFormat

public static FileFormatInfo detectFileFormat(java.lang.String fileName)
                                           throws java.lang.Exception
Detects and returns the information about a format of a document stored in a disk file.

Even if this method detects the document format, it does not guarantee that the specified document is valid. This method only detects the document format by reading data that is sufficient for detection. To fully verify that a document is valid you need to load the document into a Document object.

This method throws FileCorruptedException when the format is recognized, but the detection cannot complete because of corruption.

Parameters:
fileName - The file name.
Returns:
A FileFormatInfo object that contains the detected information.

extensionToSaveFormat

public static int extensionToSaveFormat(java.lang.String extension)
Converts a file name extension into a SaveFormat value.

If the extension cannot be recognized, returns SaveFormat.UNKNOWN.

Parameters:
extension - The file extension. Can be with or without a leading dot. Case-insensitive.

imageTypeToExtension

public static java.lang.String imageTypeToExtension(int imageType)
Converts an Aspose.Words image type enumerated value into a file extension. The returned extension is a lower-case string with a leading dot.
Parameters:
imageType - A ImageType value.

loadFormatToExtension

public static java.lang.String loadFormatToExtension(int loadFormat)
Converts a load format enumerated value into a file extension. The returned extension is a lower-case string with a leading dot.

The SaveFormat.WORD_ML value is converted to ".wml".

Parameters:
loadFormat - A LoadFormat value.

loadFormatToSaveFormat

public static int loadFormatToSaveFormat(int loadFormat)
Converts a LoadFormat value to a SaveFormat value if possible.
Parameters:
loadFormat - A LoadFormat value.

saveFormatToExtension

public static java.lang.String saveFormatToExtension(int saveFormat)
Converts a save format enumerated value into a file extension. The returned extension is a lower-case string with a leading dot.

The SaveFormat.WORD_ML value is converted to ".wml".

The SaveFormat.FLAT_OPC value is converted to ".fopc".

Parameters:
saveFormat - A SaveFormat value.

saveFormatToLoadFormat

public static int saveFormatToLoadFormat(int saveFormat)
Converts a SaveFormat value to a LoadFormat value if possible.
Parameters:
saveFormat - A SaveFormat value.

See Also:
          Aspose.Words Documentation - the home page for the Aspose.Words Product Documentation.
          Aspose.Words Support Forum - our preferred method of support.