src/org/ohmage/jee/filter/GzipFilter.java
private Map<String, String[]> gunzipRequest(
			final HttpServletRequest httpRequest,
			final HttpServletResponse httpResponse) {
		
		// Get the request's InputStream.
		InputStream requestInputStream;
		try {
			requestInputStream = httpRequest.getInputStream();
		}
		catch(IOException e) {
			LOGGER.info("Could not connect to the request's input stream.", e);
			httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST);
			return null;
		}
		
		// Pass it through the GZIP input stream.
		GZIPInputStream gzipInputStream;
		try {
			gzipInputStream = new GZIPInputStream(requestInputStream);
		}
		catch(IOException e) {
			LOGGER.info("The content was not valid GZIP content.", e);
			
			try {
				requestInputStream.close();
			}
			catch(IOException requestIs) {
				LOGGER
					.info(
						"Could not close the request's input stream.", 
						requestIs);
			}
			
			httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST);
			return null;
		}
		
		// Retrieve the parameter list as a string.
		String parameterString;
		try {
			// This will build the parameter string.
			StringBuilder builder = new StringBuilder();
			
			// These will store the information for the current chunk.
			byte[] chunk = new byte[CHUNK_SIZE];
			int readLen = 0;
			
			while((readLen = gzipInputStream.read(chunk)) != -1) {
				builder.append(new String(chunk, 0, readLen));
			}
			
			parameterString = builder.toString();
		}
		catch(IOException e) {
			LOGGER
				.info(
					"The stream was cut off before reading was finished.",
					e);
			return null;
		}
		finally {
			try {
				gzipInputStream.close();
				gzipInputStream = null;
			}
			catch(IOException e) {
				LOGGER.info("Error closing the GZIP input stream.", e);
			}

			try {
				requestInputStream.close();
				requestInputStream = null;
			}
			catch(IOException e) {
				LOGGER.info("Error closing the request's input stream.", e);
			}
		}
		
		// Create the resulting object so that we will never return null.
		Map<String, String[]> parameterMap = new HashMap<String, String[]>();
		
		// If the parameters string is not empty, parse it for the parameters.
		if(! StringUtils.isEmptyOrWhitespaceOnly(parameterString)) {
			Map<String, List<String>> parameters = 
				new HashMap<String, List<String>>();
			
			// First, split all of the parameters apart.
			String[] keyValuePairs = 
				parameterString.split(PARAMETER_SEPARATOR);
			
			// For each of the pairs, split their key and value and store them.
			for(String keyValuePair : keyValuePairs) {
				// If the pair is empty or null, ignore it.
				if(StringUtils.isEmptyOrWhitespaceOnly(keyValuePair.trim())) {
					continue;
				}
				
				// Split the key from the value.
				String[] splitPair = 
					keyValuePair.split(PARAMETER_VALUE_SEPARATOR);
				
				// If there isn't exactly one key to one value, then there is a
				// problem, and we need to abort.
				if(splitPair.length <= 1) {
					LOGGER
						.info(
							"One of the parameter's 'pairs' did not contain a '" + 
								PARAMETER_VALUE_SEPARATOR + 
								"': " + 
								keyValuePair);
					httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); 
					return null;
				}
				else if(splitPair.length > 2) {
					LOGGER
						.info(
							"One of the parameter's 'pairs' contained multiple '" + 
								PARAMETER_VALUE_SEPARATOR + 
								"'s: " + 
								keyValuePair);
					httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); 
					return null;
				}
				
				// The key is the first part of the pair.
				String key = StringUtils.urlDecode(splitPair[0]);
				
				// The first or next value for the key is the second part of 
				// the pair.
				List<String> values = parameters.get(key);
				if(values == null) {
					values = new LinkedList<String>();
					parameters.put(key, values);
				}
				values.add(StringUtils.urlDecode(splitPair[1]));
			}
			
			// Finally, convert the values from Lists to arrays. If we are 
			// going to put a parameter parsing filter in here, we might as
			// well leave them as lists.
			for(String key : parameters.keySet()) {
				parameterMap.put(key, parameters.get(key).toArray(new String[0]));
			}
		}
		
		return parameterMap;
	}
/**
	 * Unzips the parameters using the GZIP encoding. Breaks up the parameters
	 * based on the "Content-Type" "application/x-www-form-urlencoded" 
	 * specification. Creates a map of parameter keys to their URL-decoded
	 * values.
	 * 
	 * @param httpRequest The HTTP request.
	 * 
	 * @return The parameter map of parameter keys to their URL-decoded values.
	 */
Unzips the parameters using the GZIP encoding. Breaks up the parameters
based on the "Content-Type" "application/x-www-form-urlencoded"
specification. Creates a map of parameter keys to their URL-decoded
values.

@param httpRequest The HTTP request.

@return The parameter map of parameter keys to their URL-decoded values.
Unzips the parameters using the GZIP encoding . Breaks up the parameters based on the " Content - Type " " application / x - www - form - urlencoded " specification . Creates a map of parameter keys to their URL - decoded values . @param httpRequest The HTTP request . @return The parameter map of parameter keys to their URL - decoded values .
private Map<String, String[]> gunzipRequest(
			final HttpServletRequest httpRequest,
			final HttpServletResponse httpResponse) {
		InputStream requestInputStream;
		try {
			requestInputStream = httpRequest.getInputStream();
		}
		catch(IOException e) {
			LOGGER.info("Could not connect to the request's input stream.", e);
			httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST);
			return null;
		}
		GZIPInputStream gzipInputStream;
		try {
			gzipInputStream = new GZIPInputStream(requestInputStream);
		}
		catch(IOException e) {
			LOGGER.info("The content was not valid GZIP content.", e);
			try {
				requestInputStream.close();
			}
			catch(IOException requestIs) {
				LOGGER
					.info(
						"Could not close the request's input stream.", 
						requestIs);
			}
			httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST);
			return null;
		}
		String parameterString;
		try {
			StringBuilder builder = new StringBuilder();
			byte[] chunk = new byte[CHUNK_SIZE];
			int readLen = 0;
			while((readLen = gzipInputStream.read(chunk)) != -1) {
				builder.append(new String(chunk, 0, readLen));
			}
			parameterString = builder.toString();
		}
		catch(IOException e) {
			LOGGER
				.info(
					"The stream was cut off before reading was finished.",
					e);
			return null;
		}
		finally {
			try {
				gzipInputStream.close();
				gzipInputStream = null;
			}
			catch(IOException e) {
				LOGGER.info("Error closing the GZIP input stream.", e);
			}
			try {
				requestInputStream.close();
				requestInputStream = null;
			}
			catch(IOException e) {
				LOGGER.info("Error closing the request's input stream.", e);
			}
		}
		Map<String, String[]> parameterMap = new HashMap<String, String[]>();
		if(! StringUtils.isEmptyOrWhitespaceOnly(parameterString)) {
			Map<String, List<String>> parameters = 
				new HashMap<String, List<String>>();
			String[] keyValuePairs = 
				parameterString.split(PARAMETER_SEPARATOR);
			for(String keyValuePair : keyValuePairs) {
				if(StringUtils.isEmptyOrWhitespaceOnly(keyValuePair.trim())) {
					continue;
				}
				String[] splitPair = 
					keyValuePair.split(PARAMETER_VALUE_SEPARATOR);
				if(splitPair.length <= 1) {
					LOGGER
						.info(
							"One of the parameter's 'pairs' did not contain a '" + 
								PARAMETER_VALUE_SEPARATOR + 
								"': " + 
								keyValuePair);
					httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); 
					return null;
				}
				else if(splitPair.length > 2) {
					LOGGER
						.info(
							"One of the parameter's 'pairs' contained multiple '" + 
								PARAMETER_VALUE_SEPARATOR + 
								"'s: " + 
								keyValuePair);
					httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); 
					return null;
				}
				String key = StringUtils.urlDecode(splitPair[0]);
				List<String> values = parameters.get(key);
				if(values == null) {
					values = new LinkedList<String>();
					parameters.put(key, values);
				}
				values.add(StringUtils.urlDecode(splitPair[1]));
			}
			for(String key : parameters.keySet()) {
				parameterMap.put(key, parameters.get(key).toArray(new String[0]));
			}
		}
		return parameterMap;
	}
private Map < String , String [ ] > gunzipRequest ( final HttpServletRequest httpRequest , final HttpServletResponse httpResponse ) { InputStream requestInputStream ; try { requestInputStream = httpRequest . getInputStream ( ) ; } catch ( IOException e ) { LOGGER . info ( "Could not connect to the request's input stream." , e ) ; httpResponse . setStatus ( HttpServletResponse . SC_BAD_REQUEST ) ; return null ; } GZIPInputStream gzipInputStream ; try { gzipInputStream = new GZIPInputStream ( requestInputStream ) ; } catch ( IOException e ) { LOGGER . info ( "The content was not valid GZIP content." , e ) ; try { requestInputStream . close ( ) ; } catch ( IOException requestIs ) { LOGGER . info ( "Could not close the request's input stream." , requestIs ) ; } httpResponse . setStatus ( HttpServletResponse . SC_BAD_REQUEST ) ; return null ; } String parameterString ; try { StringBuilder builder = new StringBuilder ( ) ; byte [ ] chunk = new byte [ CHUNK_SIZE ] ; int readLen = 0 ; while ( ( readLen = gzipInputStream . read ( chunk ) ) != - 1 ) { builder . append ( new String ( chunk , 0 , readLen ) ) ; } parameterString = builder . toString ( ) ; } catch ( IOException e ) { LOGGER . info ( "The stream was cut off before reading was finished." , e ) ; return null ; } finally { try { gzipInputStream . close ( ) ; gzipInputStream = null ; } catch ( IOException e ) { LOGGER . info ( "Error closing the GZIP input stream." , e ) ; } try { requestInputStream . close ( ) ; requestInputStream = null ; } catch ( IOException e ) { LOGGER . info ( "Error closing the request's input stream." , e ) ; } } Map < String , String [ ] > parameterMap = new HashMap < String , String [ ] > ( ) ; if ( ! StringUtils . isEmptyOrWhitespaceOnly ( parameterString ) ) { Map < String , List < String > > parameters = new HashMap < String , List < String > > ( ) ; String [ ] keyValuePairs = parameterString . split ( PARAMETER_SEPARATOR ) ; for ( String keyValuePair : keyValuePairs ) { if ( StringUtils . isEmptyOrWhitespaceOnly ( keyValuePair . trim ( ) ) ) { continue ; } String [ ] splitPair = keyValuePair . split ( PARAMETER_VALUE_SEPARATOR ) ; if ( splitPair . length <= 1 ) { LOGGER . info ( "One of the parameter's 'pairs' did not contain a '" + PARAMETER_VALUE_SEPARATOR + "': " + keyValuePair ) ; httpResponse . setStatus ( HttpServletResponse . SC_BAD_REQUEST ) ; return null ; } else if ( splitPair . length > 2 ) { LOGGER . info ( "One of the parameter's 'pairs' contained multiple '" + PARAMETER_VALUE_SEPARATOR + "'s: " + keyValuePair ) ; httpResponse . setStatus ( HttpServletResponse . SC_BAD_REQUEST ) ; return null ; } String key = StringUtils . urlDecode ( splitPair [ 0 ] ) ; List < String > values = parameters . get ( key ) ; if ( values == null ) { values = new LinkedList < String > ( ) ; parameters . put ( key , values ) ; } values . add ( StringUtils . urlDecode ( splitPair [ 1 ] ) ) ; } for ( String key : parameters . keySet ( ) ) { parameterMap . put ( key , parameters . get ( key ) . toArray ( new String [ 0 ] ) ) ; } } return parameterMap ; }
Unzips the parameters using the GZIP encoding.
Unzips the parameters using the GZIP encoding .
// Get the request's InputStream. // Pass it through the GZIP input stream. // Retrieve the parameter list as a string. // This will build the parameter string. // These will store the information for the current chunk. // Create the resulting object so that we will never return null. // If the parameters string is not empty, parse it for the parameters. // First, split all of the parameters apart. // For each of the pairs, split their key and value and store them. // If the pair is empty or null, ignore it. // Split the key from the value. // If there isn't exactly one key to one value, then there is a // problem, and we need to abort. // The key is the first part of the pair. // The first or next value for the key is the second part of  // the pair. // Finally, convert the values from Lists to arrays. If we are  // going to put a parameter parsing filter in here, we might as // well leave them as lists.