com.sun.star.lib.uno.adapter.ByteArrayToXInputStreamAdapter Java Examples

The following examples show how to use com.sun.star.lib.uno.adapter.ByteArrayToXInputStreamAdapter. 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: StreamOpenOfficeDocumentConverter.java    From translationstudio8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Load and export.
 * @param inputStream
 *            the input stream
 * @param importOptions
 *            the import options
 * @param outputStream
 *            the output stream
 * @param exportOptions
 *            the export options
 * @throws Exception
 *             the exception
 */
@SuppressWarnings("unchecked")
private void loadAndExport(InputStream inputStream, Map/* <String,Object> */importOptions,
		OutputStream outputStream, Map/* <String,Object> */exportOptions) throws Exception {
	XComponentLoader desktop = openOfficeConnection.getDesktopObject();

	Map/* <String,Object> */loadProperties = new HashMap();
	loadProperties.putAll(getDefaultLoadProperties());
	loadProperties.putAll(importOptions);
	// doesn't work using InputStreamToXInputStreamAdapter; probably because
	// it's not XSeekable
	// property("InputStream", new
	// InputStreamToXInputStreamAdapter(inputStream))
	loadProperties.put("InputStream", new ByteArrayToXInputStreamAdapter(IOUtils.toByteArray(inputStream))); //$NON-NLS-1$

	XComponent document = desktop.loadComponentFromURL(
			"private:stream", "_blank", 0, toPropertyValues(loadProperties)); //$NON-NLS-1$ //$NON-NLS-2$
	if (document == null) {
		throw new OPException(Messages.getString("ooconverter.StreamOpenOfficeDocumentConverter.6")); //$NON-NLS-1$
	}

	refreshDocument(document);

	Map/* <String,Object> */storeProperties = new HashMap();
	storeProperties.putAll(exportOptions);
	storeProperties.put("OutputStream", new OutputStreamToXOutputStreamAdapter(outputStream)); //$NON-NLS-1$

	try {
		XStorable storable = (XStorable) UnoRuntime.queryInterface(XStorable.class, document);
		storable.storeToURL("private:stream", toPropertyValues(storeProperties)); //$NON-NLS-1$
	} finally {
		document.dispose();
	}
}
 
Example #2
Source File: AbstractInliner.java    From yarg with Apache License 2.0 6 votes vote down vote up
protected XPropertySet buildImageProperties(XGraphicProvider xGraphicProvider, Object oImage, byte[] imageContent)
        throws Exception {
    XPropertySet imageProperties = as(XPropertySet.class, oImage);

    PropertyValue[] propValues = new PropertyValue[]{new PropertyValue()};
    propValues[0].Name = "InputStream";
    propValues[0].Value = new ByteArrayToXInputStreamAdapter(imageContent);

    XGraphic graphic = xGraphicProvider.queryGraphic(propValues);
    if (graphic != null) {
        imageProperties.setPropertyValue("Graphic", graphic);

        imageProperties.setPropertyValue("HoriOrient", HoriOrientation.NONE);
        imageProperties.setPropertyValue("VertOrient", HoriOrientation.NONE);

        imageProperties.setPropertyValue("HoriOrientPosition", 0);
        imageProperties.setPropertyValue("VertOrientPosition", 0);
    }

    return imageProperties;
}
 
Example #3
Source File: StreamOpenOfficeDocumentConverter.java    From tmxeditor8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Load and export.
 * @param inputStream
 *            the input stream
 * @param importOptions
 *            the import options
 * @param outputStream
 *            the output stream
 * @param exportOptions
 *            the export options
 * @throws Exception
 *             the exception
 */
@SuppressWarnings("unchecked")
private void loadAndExport(InputStream inputStream, Map/* <String,Object> */importOptions,
		OutputStream outputStream, Map/* <String,Object> */exportOptions) throws Exception {
	XComponentLoader desktop = openOfficeConnection.getDesktopObject();

	Map/* <String,Object> */loadProperties = new HashMap();
	loadProperties.putAll(getDefaultLoadProperties());
	loadProperties.putAll(importOptions);
	// doesn't work using InputStreamToXInputStreamAdapter; probably because
	// it's not XSeekable
	// property("InputStream", new
	// InputStreamToXInputStreamAdapter(inputStream))
	loadProperties.put("InputStream", new ByteArrayToXInputStreamAdapter(IOUtils.toByteArray(inputStream))); //$NON-NLS-1$

	XComponent document = desktop.loadComponentFromURL(
			"private:stream", "_blank", 0, toPropertyValues(loadProperties)); //$NON-NLS-1$ //$NON-NLS-2$
	if (document == null) {
		throw new OPException(Messages.getString("ooconverter.StreamOpenOfficeDocumentConverter.6")); //$NON-NLS-1$
	}

	refreshDocument(document);

	Map/* <String,Object> */storeProperties = new HashMap();
	storeProperties.putAll(exportOptions);
	storeProperties.put("OutputStream", new OutputStreamToXOutputStreamAdapter(outputStream)); //$NON-NLS-1$

	try {
		XStorable storable = (XStorable) UnoRuntime.queryInterface(XStorable.class, document);
		storable.storeToURL("private:stream", toPropertyValues(storeProperties)); //$NON-NLS-1$
	} finally {
		document.dispose();
	}
}