src/org/ohmage/domain/Media.java
public final void writeFile(final File destination)
		throws DomainException {
		
		// Get the image data.
		InputStream contents = getContentStream();
		
		if(contents == null) {
			throw new DomainException("The contents parameter is null.");
		}
		
		// Connect to the file that should write it.
		FileOutputStream fos;
		try {
			fos = new FileOutputStream(destination);
		}
		catch(SecurityException e) {
			throw
				new DomainException(
					"The file is not allowed to be created.",
					e);
		}
		catch(FileNotFoundException e) {
			throw new DomainException("The file cannot be created.", e);
		}
		
		// Write the image data.
		try {
			int bytesRead;
			byte[] buffer = new byte[4096];
			while((bytesRead = contents.read(buffer)) != -1) {
				fos.write(buffer, 0, bytesRead);
			}
		}
		catch(IOException e) {
			throw
				new DomainException(
					"Error reading or writing the data.",
					e);
		}
		finally {
			try {
				fos.close();
			}
			catch(IOException e) {
				throw new DomainException("Could not close the file.", e);
			}
		}
	}
/**
	 * Writes the media data to the given file. 
	 * 
	 * @param destination The file to write the image to.
	 * 
	 * @throws DomainException There was an error reading the data
	 * 						   or writing the file.
	 * 
	 */
Writes the media data to the given file.

@param destination The file to write the image to.

@throws DomainException There was an error reading the data
or writing the file.
Writes the media data to the given file . @param destination The file to write the image to . @throws DomainException There was an error reading the data or writing the file .
public final void writeFile(final File destination)
		throws DomainException {
		InputStream contents = getContentStream();
		if(contents == null) {
			throw new DomainException("The contents parameter is null.");
		}
		FileOutputStream fos;
		try {
			fos = new FileOutputStream(destination);
		}
		catch(SecurityException e) {
			throw
				new DomainException(
					"The file is not allowed to be created.",
					e);
		}
		catch(FileNotFoundException e) {
			throw new DomainException("The file cannot be created.", e);
		}
		try {
			int bytesRead;
			byte[] buffer = new byte[4096];
			while((bytesRead = contents.read(buffer)) != -1) {
				fos.write(buffer, 0, bytesRead);
			}
		}
		catch(IOException e) {
			throw
				new DomainException(
					"Error reading or writing the data.",
					e);
		}
		finally {
			try {
				fos.close();
			}
			catch(IOException e) {
				throw new DomainException("Could not close the file.", e);
			}
		}
	}
public final void writeFile ( final File destination ) throws DomainException { InputStream contents = getContentStream ( ) ; if ( contents == null ) { throw new DomainException ( "The contents parameter is null." ) ; } FileOutputStream fos ; try { fos = new FileOutputStream ( destination ) ; } catch ( SecurityException e ) { throw new DomainException ( "The file is not allowed to be created." , e ) ; } catch ( FileNotFoundException e ) { throw new DomainException ( "The file cannot be created." , e ) ; } try { int bytesRead ; byte [ ] buffer = new byte [ 4096 ] ; while ( ( bytesRead = contents . read ( buffer ) ) != - 1 ) { fos . write ( buffer , 0 , bytesRead ) ; } } catch ( IOException e ) { throw new DomainException ( "Error reading or writing the data." , e ) ; } finally { try { fos . close ( ) ; } catch ( IOException e ) { throw new DomainException ( "Could not close the file." , e ) ; } } }
Writes the media data to the given file.
Writes the media data to the given file .
// Get the image data. // Connect to the file that should write it. // Write the image data.