MCPcopy Create free account
hub / github.com/LibreOffice/core / WriteBytesToStream

Method WriteBytesToStream

odk/examples/java/Storage/TestHelper.java:38–118  ·  view source on GitHub ↗
( XStream xStream,
                                        String sStreamName,
                                        String sMediaType,
                                        boolean bCompressed,
                                        byte[] pBytes )

Source from the content-addressed store, hash-verified

36 }
37
38 public boolean WriteBytesToStream( XStream xStream,
39 String sStreamName,
40 String sMediaType,
41 boolean bCompressed,
42 byte[] pBytes )
43 {
44 // get output stream of substream
45 XOutputStream xOutput = xStream.getOutputStream();
46 if ( xOutput == null )
47 {
48 Error( "Can't get XOutputStream implementation from substream '" + sStreamName + "'!" );
49 return false;
50 }
51
52 // get XTruncate implementation from output stream
53 XTruncate xTruncate = UnoRuntime.queryInterface( XTruncate.class, xOutput );
54 if ( xTruncate == null )
55 {
56 Error( "Can't get XTruncate implementation from substream '" + sStreamName + "'!" );
57 return false;
58 }
59
60 // write requested byte sequence
61 try
62 {
63 xTruncate.truncate();
64 xOutput.writeBytes( pBytes );
65 }
66 catch( Exception e )
67 {
68 Error( "Can't write to stream '" + sStreamName + "', exception: " + e );
69 return false;
70 }
71
72 // get access to the XPropertySet interface
73 XPropertySet xPropSet = UnoRuntime.queryInterface( XPropertySet.class, xStream );
74 if ( xPropSet == null )
75 {
76 Error( "Can't get XPropertySet implementation from substream '" + sStreamName + "'!" );
77 return false;
78 }
79
80 // set properties to the stream
81 try
82 {
83 xPropSet.setPropertyValue( "MediaType", sMediaType );
84 xPropSet.setPropertyValue( "Compressed", Boolean.valueOf( bCompressed ) );
85 }
86 catch( Exception e )
87 {
88 Error( "Can't set properties to substream '" + sStreamName + "', exception: " + e );
89 return false;
90 }
91
92 // check size property of the stream
93 try
94 {
95 int nSize = AnyConverter.toInt( xPropSet.getPropertyValue( "Size" ) );

Callers 3

WriteBytesToSubstreamMethod · 0.95
WBToSubstrOfEncrMethod · 0.95

Calls 9

ErrorMethod · 0.95
queryInterfaceMethod · 0.95
toIntMethod · 0.95
disposeMethod · 0.65
getOutputStreamMethod · 0.45
truncateMethod · 0.45
writeBytesMethod · 0.45
setPropertyValueMethod · 0.45
getPropertyValueMethod · 0.45

Tested by

no test coverage detected