ColdFusion CFFile vs. Java java.io.BufferedOutputStream

<!---
	Test the Java BufferedOutputStream. In this case we are
	testing the output stream with a buffer size of 2048 bytes,
	but we can set it to anything we want.
--->
<cftimer label="BufferedFileOutput Stream Test" type="outline">
 
	<!---
		Kill extra output. We want to do this because otherwise,
		we are creating [intIterations] amount of white space
		on the page. No need for that.
	--->
	<cfsilent>
 
		<!--- Get the file name to write to. --->
		<cfset strFilePath = ExpandPath( "./bio_output2.txt" ) />
 
		<!---
			Create the buffered file output stream. When
			creating the buffered file output stream, we have
			to initialize it with a Java File Output stream,
			which we, in turn, have to initialize with a Java
			File Output Stream, which itself needs to be
			initialized with a Java File object (which we
			initialize with the path to the file we want
			to create).
 
			Additionally, the second argument of the buffered
			output stream is the size of the buffer. In this
			case we are using 2048 bytes.
		--->
		<cfset bosOutput = CreateObject(
			"java",
			"java.io.BufferedOutputStream"
			).Init(
				CreateObject(
					"java",
					"java.io.FileOutputStream"
					).Init(
						CreateObject(
							"java",
							"java.io.File"
							).Init(
								strFilePath
								)
						),
				JavaCast( "int", 2048 )
			) />
 
 
		<!---
			Loop over the iterations to build up the data. For
			each iteration, we are going to select a random
			string and write that string directly to the
			buffered output stream which should write it
			directly to file output stream once the buffer is
			populated with enough data.
		--->
		<cfloop
			index="intI"
			from="1"
			to="#intIterations#"
			step="1">
 
			<!---
				Create the random string. In this case we are
				creating the string prior to buffer writing
				because we will need it to get the length of
				the data.
			--->
			<cfset strText = (
				"I am crazy about " &
				arrParts[ RandRange( 1, 7 ) ] &
				Chr( 13) & Chr( 10 )
				) />
 
 
			<!---
				Add a random string to the buffered file output
				stream. We want to write the entire byte array
				to the output stream.
			--->
			<cfset bosOutput.Write(
				strText.GetBytes(),
				JavaCast( "int", 0 ),
				strText.Length()
				) />
 
		</cfloop>
 
	</cfsilent>
 
	<!--- Output name of file. --->
	#strFilePath#
 
</cftimer>

For Cut-and-Paste