src/org/ohmage/query/impl/DocumentQueries.java
private void updateContents(String documentId, byte[] contents) throws DataAccessException {
		if(contents == null) {
			return;
		}
		
		// Lookup the document's URL.
		String documentUrl = getDocumentUrl(documentId);
		
		// Update the size in the database.
		try {
			getJdbcTemplate().update(SQL_UPDATE_SIZE, new Object[] { contents.length, documentId });
		}
		catch(org.springframework.dao.DataAccessException e) {
			throw new DataAccessException("Error executing SQL '" + SQL_UPDATE_SIZE + "' with parameters: " + contents.length + ", " + documentId, e);
		}
		
		// Write the new contents to the document.
		try {
			// TODO: If we are really going to support any URL, then we need to
			// find a way to be able to write to URLs as well. Currently, we 
			// are only writing to files, so that is what is "hard coded." But,
			// we really need to switch the writer based on the URL.
			FileOutputStream fileOutputStream = new FileOutputStream(new URL(documentUrl).getFile());
			fileOutputStream.write(contents);
			fileOutputStream.flush();
			fileOutputStream.close();
		} 
		catch(MalformedURLException e) {
			throw new DataAccessException("The URL pointing to this resource is broken. This could be a major issue.", e);
		} 
		catch(FileNotFoundException e) {
			throw new DataAccessException("The file that this URL points to is missing. This could be a major issue.", e);
		}
		catch(SecurityException e) {
			throw new DataAccessException("We don't have permissions to open a connection or write to a document.", e);
		}
		catch (IOException e) {
			throw new DataAccessException("There was an error writing to the URL.", e);
		}
	}
/**
	 * Updates the file's size in the database and updates the contents on the
	 * disk. If the contents is null, nothing happens.
	 * 
	 * @param documentId The unique identifier for the document.
	 * 
	 * @param contents The new contents of the document.
	 */
Updates the file's size in the database and updates the contents on the
disk. If the contents is null, nothing happens.

@param documentId The unique identifier for the document.

@param contents The new contents of the document.
Updates the file ' s size in the database and updates the contents on the disk . If the contents is null nothing happens . @param documentId The unique identifier for the document . @param contents The new contents of the document .
private void updateContents(String documentId, byte[] contents) throws DataAccessException {
		if(contents == null) {
			return;
		}
		String documentUrl = getDocumentUrl(documentId);
		try {
			getJdbcTemplate().update(SQL_UPDATE_SIZE, new Object[] { contents.length, documentId });
		}
		catch(org.springframework.dao.DataAccessException e) {
			throw new DataAccessException("Error executing SQL '" + SQL_UPDATE_SIZE + "' with parameters: " + contents.length + ", " + documentId, e);
		}
		try {
			FileOutputStream fileOutputStream = new FileOutputStream(new URL(documentUrl).getFile());
			fileOutputStream.write(contents);
			fileOutputStream.flush();
			fileOutputStream.close();
		} 
		catch(MalformedURLException e) {
			throw new DataAccessException("The URL pointing to this resource is broken. This could be a major issue.", e);
		} 
		catch(FileNotFoundException e) {
			throw new DataAccessException("The file that this URL points to is missing. This could be a major issue.", e);
		}
		catch(SecurityException e) {
			throw new DataAccessException("We don't have permissions to open a connection or write to a document.", e);
		}
		catch (IOException e) {
			throw new DataAccessException("There was an error writing to the URL.", e);
		}
	}
private void updateContents ( String documentId , byte [ ] contents ) throws DataAccessException { if ( contents == null ) { return ; } String documentUrl = getDocumentUrl ( documentId ) ; try { getJdbcTemplate ( ) . update ( SQL_UPDATE_SIZE , new Object [ ] { contents . length , documentId } ) ; } catch ( org . springframework . dao . DataAccessException e ) { throw new DataAccessException ( "Error executing SQL '" + SQL_UPDATE_SIZE + "' with parameters: " + contents . length + ", " + documentId , e ) ; } try { FileOutputStream fileOutputStream = new FileOutputStream ( new URL ( documentUrl ) . getFile ( ) ) ; fileOutputStream . write ( contents ) ; fileOutputStream . flush ( ) ; fileOutputStream . close ( ) ; } catch ( MalformedURLException e ) { throw new DataAccessException ( "The URL pointing to this resource is broken. This could be a major issue." , e ) ; } catch ( FileNotFoundException e ) { throw new DataAccessException ( "The file that this URL points to is missing. This could be a major issue." , e ) ; } catch ( SecurityException e ) { throw new DataAccessException ( "We don't have permissions to open a connection or write to a document." , e ) ; } catch ( IOException e ) { throw new DataAccessException ( "There was an error writing to the URL." , e ) ; } }
Updates the file's size in the database and updates the contents on the
 disk.
Updates the file ' s size in the database and updates the contents on the disk .
// Lookup the document's URL. // Update the size in the database. // Write the new contents to the document. // TODO: If we are really going to support any URL, then we need to // find a way to be able to write to URLs as well. Currently, we  // are only writing to files, so that is what is "hard coded." But, // we really need to switch the writer based on the URL.