public String CreateTempFile(XMultiServiceFactory xMSF) { String sResult = null; // try to get temporary file representation XPropertySet xTempFileProps = null; try { Object oTempFile = xMSF.createInstance("com.sun.star.io.TempFile"); xTempFileProps = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, oTempFile); } catch (Exception e) { } if (xTempFileProps != null) { try { xTempFileProps.setPropertyValue("RemoveFile", new Boolean(false)); sResult = AnyConverter.toString(xTempFileProps.getPropertyValue("Uri")); } catch (Exception e) { Error("Can't control TempFile properties, exception: " + e); } } else { Error("Can't create temporary file representation!"); } // close temporary file explicitly try { XStream xStream = (XStream) UnoRuntime.queryInterface(XStream.class, xTempFileProps); if (xStream != null) { XOutputStream xOut = xStream.getOutputStream(); if (xOut != null) xOut.closeOutput(); XInputStream xIn = xStream.getInputStream(); if (xIn != null) xIn.closeInput(); } else Error("Can't close TempFile!"); } catch (Exception e) { Error("Can't close TempFile, exception: " + e); } return sResult; }
public boolean InternalCheckStream( XStream xStream, String sName, String sMediaType, boolean bCompressed, byte[] pBytes, boolean bCheckCompressed) { // get input stream of substream XInputStream xInput = xStream.getInputStream(); if (xInput == null) { Error("Can't get XInputStream implementation from substream '" + sName + "'!"); return false; } byte pContents[][] = new byte[1][]; // ??? // read contents try { xInput.readBytes(pContents, pBytes.length + 1); } catch (Exception e) { Error("Can't read from stream '" + sName + "', exception: " + e); return false; } // check size of stream data if (pContents.length == 0) { Error("SubStream '" + sName + "' reading produced disaster!"); return false; } if (pBytes.length != pContents[0].length) { Error( "SubStream '" + sName + "' contains wrong amount of data! (" + pContents[0].length + "/" + pBytes.length + ")"); return false; } // check stream data for (int ind = 0; ind < pBytes.length; ind++) { if (pBytes[ind] != pContents[0][ind]) { Error( "SubStream '" + sName + "' contains wrong data! ( byte num. " + ind + " should be " + pBytes[ind] + " but it is " + pContents[0][ind] + ")"); return false; } } // check properties boolean bOk = false; // get access to the XPropertySet interface XPropertySet xPropSet = (XPropertySet) UnoRuntime.queryInterface(XPropertySet.class, xStream); if (xPropSet != null) { try { // get "MediaType" and "Size" properties and control there values String sPropMediaType = AnyConverter.toString(xPropSet.getPropertyValue("MediaType")); long nPropSize = AnyConverter.toLong(xPropSet.getPropertyValue("Size")); boolean bPropCompress = AnyConverter.toBoolean(xPropSet.getPropertyValue("Compressed")); bOk = true; if (!sPropMediaType.equals(sMediaType)) { Error( "'MediaType' property contains wrong value for stream '" + sName + "',\nexpected: '" + sMediaType + "', set: '" + sPropMediaType + "'!"); bOk = false; } if (nPropSize != pBytes.length) { Error("'Size' property contains wrong value for stream'" + sName + "'!"); bOk = false; } if (bCheckCompressed && bPropCompress != bCompressed) { Error("'Compressed' property contains wrong value for stream'" + sName + "'!"); bOk = false; } } catch (Exception e) { Error("Can't get properties of substream '" + sName + "', exception: " + e); } } else { Error("Can't get XPropertySet implementation from stream '" + sName + "'!"); } return bOk; }
public boolean compareRawMethodsOnEncrStream(XStorage xStorage, String sStreamName) { XStorageRawAccess xRawStorage; try { xRawStorage = (XStorageRawAccess) UnoRuntime.queryInterface(XStorageRawAccess.class, xStorage); } catch (Exception e) { Error("Can't get raw access to the storage, exception : " + e + "!"); return false; } if (xRawStorage == null) { Error("Can't get raw access to the storage!"); return false; } XInputStream xHeadRawStream = null; try { xHeadRawStream = xRawStorage.getRawEncrStreamElement(sStreamName); } catch (Exception e) { Error( "Can't open encrypted stream '" + sStreamName + "' in raw mode with header, exception : " + e + "!"); } XInputStream xPlainRawStream = null; try { xPlainRawStream = xRawStorage.getPlainRawStreamElement(sStreamName); } catch (Exception e) { Error( "Can't open encrypted stream '" + sStreamName + "' in raw mode with header, exception : " + e + "!"); } if (xHeadRawStream == null || xPlainRawStream == null) { Error("Can't open encrypted stream '" + sStreamName + "' in raw modes!"); return false; } try { byte pData[][] = new byte[1][38]; if (xHeadRawStream.readBytes(pData, 38) != 38) { Error("Can't read header of encrypted stream '" + sStreamName + "' raw representations!"); return false; } if (pData[0][0] != 0x4d || pData[0][1] != 0x4d || pData[0][2] != 0x02 || pData[0][3] != 0x05) { Error( "No signature in the header of encrypted stream '" + sStreamName + "' raw representations!"); return false; } int nVariableHeaderLength = (pData[0][30] + pData[0][31] * 0x100) // salt length + (pData[0][32] + pData[0][33] * 0x100) // iv length + (pData[0][34] + pData[0][35] * 0x100) // digest length + (pData[0][36] + pData[0][37] * 0x100); // mediatype length xHeadRawStream.skipBytes(nVariableHeaderLength); byte pRawData1[][] = new byte[1][32000]; byte pRawData2[][] = new byte[1][32000]; int nRead1 = 0; int nRead2 = 0; do { nRead1 = xHeadRawStream.readBytes(pRawData1, 32000); nRead2 = xPlainRawStream.readBytes(pRawData2, 32000); if (nRead1 != nRead2) { Error( "The encrypted stream '" + sStreamName + "' raw representations have different size! nRead1 - nRead2 = " + (new Integer(nRead1 - nRead2)).toString()); return false; } for (int nInd = 0; nInd < nRead1; nInd++) if (pRawData1[0][nInd] != pRawData2[0][nInd]) { Error( "The encrypted stream '" + sStreamName + "' raw representations have different data!"); return false; } } while (nRead1 == 32000); } catch (Exception e) { Error( "Can't compare stream '" + sStreamName + "' raw representations, exception : " + e + "!"); return false; } return true; }