/*
@see javax.servlet.ServletResponse#getOutputStream()
323411
@Override
    public ServletOutputStream getOutputStream() throws IOException {
        if (TraceComponent.isAnyTracingEnabled() && tc.isDebugEnabled()) {
            Tr.debug(tc, "getOutputStream: " + this);
        }
        if (null != this.outWriter) {
            throw new IllegalStateException("Output writer already obtained");
        }
        this.streamActive = true;
        return this.outStream;
    }
1008344
public OutputStream getOutputStream()
    {
        OutputStream stream=null;
        try
        {
            stream=this.commPort.getOutputStream();
        }
        catch(IOException exception)
        {
            throw new FaxException("Unable to extract output stream.",exception);
        }
        
        return stream;
    }
640751
public static void writeToOutputStream(String s, OutputStream output) throws IOException {
		writeToOutputStream(s, output, null);
	}
342769
InputStream getInputStream() {
    InputStream result = (InputStream) streams.get();
    return ((result == null) ? defaultInputStream : result);
  }
607735
@Override
    public InputStream getInputStream() {
        try {
            return property.getBinary().getStream();
        } catch (final RepositoryException e) {
            throw new RepositoryRuntimeException(e);
        }
    }
1171217
public ServletOutputStream getOutputStream() {
        final boolean isTraceOn = com.ibm.ejs.ras.TraceComponent.isAnyTracingEnabled();
        if (isTraceOn&&logger.isLoggable (Level.FINE))  //306998.15
            logger.entering(CLASS_NAME,"getOutputStream","gotWriter="+String.valueOf(_gotWriter)+" ["+this+"]");

        if (!_ignoreStateErrors && _gotWriter) {

            if (isTraceOn&&logger.isLoggable (Level.FINE))  //306998.15
                logger.exiting(CLASS_NAME,"getOutputStream","throw IllegalStateException");

            throw new IllegalStateException(nls.getString("Writer.already.obtained", "Writer already obtained"));
        }

        //PK89810 Start
        if(!(WCCustomProperties.FINISH_RESPONSE_ON_CLOSE) || ! _gotOutputStream)                
        {
            _gotOutputStream = true;

            // LIBERTY _bufferedOut.init(_rawOut, getBufferSize());
            // LIBERTY _bufferedOut.setLimit(_contentLength);
            // LIBERTY _bufferedOut.setResponse(_response);
            // LIBERTY _responseBuffer = _bufferedOut;
        } //PK89810 End
        this.fireOutputStreamRetrievedEvent(_bufferedOut);

        if (isTraceOn&&logger.isLoggable (Level.FINE))  //306998.15
            logger.exiting(CLASS_NAME,"getOutputStream");

        return _bufferedOut;
    }
156833
public synchronized InputStream getInputStream() throws IOException {
        if (!connected) {
            connect();
        }

        // Nothing to return
        if (responseCode == HTTP_NOT_FOUND) {
            throw new FileNotFoundException(url.toString());
        }
        int length;

        if (inputStream == null) {
            return null;
        }

        // "De-chunk" the output stream
        else if ("chunked".equalsIgnoreCase(getHeaderField("Transfer-Encoding"))) {
            if (!(inputStream instanceof ChunkedInputStream)) {
                inputStream = new ChunkedInputStream(inputStream);
            }
        }

        // Make sure we don't wait forever, if the content-length is known
        else if ((length = getHeaderFieldInt("Content-Length", -1)) >= 0) {
            if (!(inputStream instanceof FixedLengthInputStream)) {
                inputStream = new FixedLengthInputStream(inputStream, length);
            }
        }
        return inputStream;
    }
154292
private OutputStream getOutputStream(final String s) {
        return new OutputStream() {

            StringBuffer o = new StringBuffer();
            boolean done = false;

            @Override
            public void write(int b) throws IOException {
                if (b == '\n' && !sync) {
                    synchronized (conf) {
                        System.out.printf("[%s] %s \n", s, o.toString());
                    }
                    o = new StringBuffer();
                }
                o.append((char) b);
            }

            @Override
            public void flush() throws IOException {
                if (!done) {
                    if (sync) {
                        System.out.printf("************* %s **************\n", s);
                    }
                    System.out.printf(o.toString());
                    done = true;
                }
            }
        };
    }
68969
@SuppressWarnings("unchecked")
	@Override
	public InputStream getInputStream(HttpServletRequest request,
			HttpServletResponse response) throws IOException {

		final String sourceMethod = "getInputStream"; //$NON-NLS-1$
		CacheEntry entry = null;
		String key = null;
		IAggregator aggr = (IAggregator)request.getAttribute(IAggregator.AGGREGATOR_REQATTRNAME);
		List<String> cacheInfoReport = null;
		ModuleList moduleList = null;
		boolean cacheKeyGenMutexAcquired = false;

		if (_isReportCacheInfo) {
			cacheInfoReport = (List<String>)request.getAttribute(LAYERCACHEINFO_PROPNAME);
			if (cacheInfoReport != null) {
				cacheInfoReport.clear();
			}
		}
		if (log.isLoggable(Level.FINEST) && cacheInfoReport == null) {
			cacheInfoReport = new LinkedList<String>();
		}
		try {
			IOptions options = aggr.getOptions();
			ICacheManager mgr = aggr.getCacheManager();
			boolean ignoreCached = RequestUtil.isIgnoreCached(request);
			boolean isSourceMapsEnabled = RequestUtil.isSourceMapsEnabled(request);
			InputStream result;
			long lastModified = getLastModified(request);
			CacheEntry newEntry = new CacheEntry(_id, _cacheKey, lastModified);
			CacheEntry existingEntry = null;

			if (ignoreCached) {
				request.setAttribute(NOCACHE_RESPONSE_REQATTRNAME, Boolean.TRUE);
			}
			if (options.isDevelopmentMode()) {
				synchronized(this) {
					// See if we need to discard previously built LayerBuilds
					if (lastModified > _lastModified) {
						if (cacheInfoReport != null) {
							cacheInfoReport.add("update_lastmod2"); //$NON-NLS-1$
						}
						_lastModified = lastModified;
						_cacheKeyGenerators = null;
					}
				}
			}

			if (_cacheKeyGenerators == null) {
				// The cache key generator for this layer hasn't been created yet.  Attempt
				// to grab the mutex.
				try {
					SignalUtil.aquire(_cacheKeyGenMutex, sourceClass, sourceMethod);
				} catch (InterruptedException e) {
					throw new RuntimeException(e);
				}
				if (_cacheKeyGenerators == null) {
					// We're the first thread for this layer.  Set flag and proceed to build the
					// layer.  We'll release the mutex and let other thread through once we have
					// a cache key generator.
					cacheKeyGenMutexAcquired = true;
				} else {
					// Another thread already created the cache key generator.  Just release the
					// mutex and continue.
					_cacheKeyGenMutex.release();
				}
			}
			Map<String, ICacheKeyGenerator> cacheKeyGenerators = _cacheKeyGenerators;

			// Creata a cache key.
			key = generateCacheKey(request, cacheKeyGenerators);

			if (!ignoreCached && key != null) {
				int loopGuard = 5;
				do {
					// Try to retrieve an existing layer build using the blocking putIfAbsent.  If the return
					// value is null, then the newEntry was successfully added to the map, otherwise the
					// existing entry is returned in the buildReader and newEntry was not added.
					existingEntry = _layerBuilds.putIfAbsent(key, newEntry, options.isDevelopmentMode());
					if (cacheInfoReport != null) {
						cacheInfoReport.add(existingEntry != null ? "hit_1" : "added"); //$NON-NLS-1$ //$NON-NLS-2$
					}
					if (existingEntry != null) {
						if ((result = trySetResponse(request, response, existingEntry)) != null) {
							if (log.isLoggable(Level.FINEST)) {
								log.finest(cacheInfoReport.toString() + "\n" +  //$NON-NLS-1$
										"key:" + key +  //$NON-NLS-1$
										"\n" + existingEntry.toString()); //$NON-NLS-1$
							}
							if (_isReportCacheInfo) {
								request.setAttribute(LAYERBUILDCACHEKEY_PROPNAME, key);
							}
							return result;
						} else if (existingEntry.isDeleted()) {
							if (_layerBuilds.replace(key, existingEntry, newEntry)) {
								// entry was replaced, use newEntry
								if (cacheInfoReport != null) {
									cacheInfoReport.add("replace_1"); //$NON-NLS-1$
								}
								existingEntry = null;
							} else {
								// Existing entry was removed from the cache by another thread
								// between the time we retrieved it and the time we tried to
								// replace it.  Try to add the new entry again.
								if (cacheInfoReport != null) {
									cacheInfoReport.add("retry_add"); //$NON-NLS-1$
								}
								if (--loopGuard == 0) {
									// Should never happen, but just in case
									throw new IllegalStateException();
								}
								continue;
							}
						}
					}
					break;
				} while (true);
			}

			// putIfAbsent() succeeded and the new entry was added to the cache
			entry = (existingEntry != null) ? existingEntry : newEntry;

			LayerBuilder layerBuilder = null;

			// List of Future<IModule.ModuleReader> objects that will be used to read the module
			// data from
			List<ICacheKeyGenerator> moduleKeyGens = null;

			// Synchronize on the LayerBuild object for the build.  This will prevent multiple
			// threads from building the same output.  If more than one thread requests the same
			// output (same cache key), then the first one to grab the sync object will win and
			// the rest will wait for the first thread to finish building and then just return
			// the output from the first thread when they wake.
			synchronized(entry) {

				// Check to see if data is available one more time in case a different thread finished
				// building the output while we were blocked on the sync object.
				if (!ignoreCached && key != null && (result = trySetResponse(request, response, entry)) != null) {
					if (cacheInfoReport != null) {
						cacheInfoReport.add("hit_2"); //$NON-NLS-1$
					}
					if (log.isLoggable(Level.FINEST)) {
						log.finest(cacheInfoReport.toString() + "\n" + //$NON-NLS-1$
								"key:" + key +  //$NON-NLS-1$
								"\n" + entry.toString()); //$NON-NLS-1$
					}
					if (_isReportCacheInfo) {
						request.setAttribute(LAYERBUILDCACHEKEY_PROPNAME, key);
					}
					return result;
				}

				boolean isGzip = RequestUtil.isGzipEncoding(request);
				byte[] bytes, smbytes = null;


				// See if we already have a cached response that uses a different gzip
				// encoding option.  If we do, then just zip (or unzip) the cached
				// response
				CacheEntry otherEntry = null;
				if (key != null) {
					StringBuffer sb = new StringBuffer();
					Matcher m = GZIPFLAG_KEY_PATTERN.matcher(key);
					m.find();
					m.appendReplacement(sb,
							new StringBuffer(s_layerCacheKeyGenerators.get(0).toString())
					.append(":") //$NON-NLS-1$
					.append("1".equals(m.group(1)) ? "0" : "1") //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
					.append(":").toString() //$NON-NLS-1$
							).appendTail(sb);
					otherEntry = _layerBuilds.get(sb.toString());
				}
				if (otherEntry != null) {
					MutableObject<byte[]> sourceMapRef = isSourceMapsEnabled ? new MutableObject<byte[]>() : null;
					if (isGzip) {
						if (cacheInfoReport != null) {
							cacheInfoReport.add("zip_unzipped"); //$NON-NLS-1$
						}
						// We need gzipped and the cached entry is unzipped
						// Create the compression stream for the output
						bytes = ZipUtil.zip(otherEntry.getInputStream(request, sourceMapRef));
						if (isSourceMapsEnabled && sourceMapRef.getValue() != null) {
							smbytes = ZipUtil.zip(new ByteArrayInputStream(sourceMapRef.getValue()));
						}
					} else {
						if (cacheInfoReport != null) {
							cacheInfoReport.add("unzip_zipped"); //$NON-NLS-1$
						}
						// We need unzipped and the cached entry is zipped.  Just unzip it
						bytes = ZipUtil.unzip(otherEntry.getInputStream(request, sourceMapRef));
						if (isSourceMapsEnabled && sourceMapRef.getValue() != null) {
							// unzip the source map too
							smbytes = ZipUtil.unzip(new ByteArrayInputStream(sourceMapRef.getValue()));
						}
					}
					// Set the buildReader to the LayerBuild and release the lock by exiting the sync block
					entry.setData(bytes, smbytes);
					if (!ignoreCached) {
						_layerBuilds.replace(key, entry, entry);	// updates entry weight in map
						if (cacheInfoReport != null) {
							cacheInfoReport.add("update_weights_1"); //$NON-NLS-1$
						}
						entry.persist(mgr);
					}
				} else {
					moduleKeyGens = new LinkedList<ICacheKeyGenerator>();

					moduleList = getModules(request);

					// Remove the module list from the request to safe-guard it now that we don't
					// need it there anymore
					request.removeAttribute(MODULE_FILES_PROPNAME);

					// Create a BuildListReader from the list of Futures.  This reader will obtain a
					// ModuleReader from each of the Futures in the list and read data from each one in
					// succession until all the data has been read, blocking on each Future until the
					// reader becomes available.
					layerBuilder = new LayerBuilder(request, moduleKeyGens, moduleList);
					String layer = layerBuilder.build();
					String sourceMap = layerBuilder.getSourceMap();

					if (isGzip) {
						if (cacheInfoReport != null) {
							cacheInfoReport.add("zip"); //$NON-NLS-1$
						}
						bytes = ZipUtil.zip(new ReaderInputStream(new StringReader(layer)));
						// now compress the source map if there is one
						if (sourceMap != null) {
							smbytes = ZipUtil.zip(new ReaderInputStream(new StringReader(sourceMap)));
						}
					} else {
						bytes = layer.getBytes();
						smbytes = (sourceMap != null) ? sourceMap.getBytes() : null;
					}
					// Set the buildReader to the LayerBuild and release the lock by exiting the sync block
					entry.setData(bytes, smbytes);
					// entry will be persisted below after we determine if cache key
					// generator needs to be updated
				}
			}

			// if any of the readers included an error response, then don't cache the layer.
			if (layerBuilder != null && layerBuilder.hasErrors()) {
				request.setAttribute(NOCACHE_RESPONSE_REQATTRNAME, Boolean.TRUE);
				if (cacheInfoReport != null) {
					cacheInfoReport.add(key == null ? "error_noaction" : "error_remove"); //$NON-NLS-1$ //$NON-NLS-2$
				}
				if (key != null) {
					_layerBuilds.remove(key, entry);
				}
			} else if (layerBuilder != null) {
				if (!ignoreCached) {
					// See if we need to create or update the cache key generators
					Map<String, ICacheKeyGenerator> newKeyGens = new HashMap<String, ICacheKeyGenerator>();
					Set<String> requiredModuleListDeps = moduleList.getDependentFeatures();
					addCacheKeyGenerators(newKeyGens, s_layerCacheKeyGenerators);
					addCacheKeyGenerators(newKeyGens, aggr.getTransport().getCacheKeyGenerators());
					addCacheKeyGenerators(newKeyGens, Arrays.asList(new ICacheKeyGenerator[]{new FeatureSetCacheKeyGenerator(requiredModuleListDeps, false)}));
					addCacheKeyGenerators(newKeyGens, moduleKeyGens);

					boolean cacheKeyGeneratorsUpdated = false;
					if (!newKeyGens.equals(cacheKeyGenerators)) {
						// If we don't yet have a cache key for this layer, then get one
						// from the cache key generators, and then update the cache key for this
						// cache entry.

						synchronized(this) {
							if (_cacheKeyGenerators != null) {
								addCacheKeyGenerators(newKeyGens, _cacheKeyGenerators.values());
							}
							_cacheKeyGenerators = Collections.unmodifiableMap(newKeyGens);
						}
						if (cacheKeyGenMutexAcquired) {
							cacheKeyGenMutexAcquired = false;
							_cacheKeyGenMutex.release();
						}
						if (cacheInfoReport != null) {
							cacheInfoReport.add("update_keygen"); //$NON-NLS-1$
						}
						cacheKeyGeneratorsUpdated = true;
					}
					final String originalKey = key;
					if (key == null || cacheKeyGeneratorsUpdated) {
						if (cacheInfoReport != null) {
							cacheInfoReport.add("update_key"); //$NON-NLS-1$
						}
						key = generateCacheKey(request, newKeyGens);
					}
					if (originalKey == null || !originalKey.equals(key)) {
						/*
						 * The cache key has changed from what was originally used to put the
						 * un-built entry into the cache.  Add the LayerBuild to the cache
						 * using the new key.
						 */
						if (log.isLoggable(Level.FINE)) {
							log.fine("Key changed!  Adding layer to cache with key: " + key); //$NON-NLS-1$
						}
						final CacheEntry originalEntry = entry;
						CacheEntry updateEntry = (originalKey == null) ? entry : new CacheEntry(entry);
						CacheEntry previousEntry = _layerBuilds.putIfAbsent(key, updateEntry, options.isDevelopmentMode());
						if (cacheInfoReport != null) {
							cacheInfoReport.add(previousEntry == null ? "update_add" : "update_hit"); //$NON-NLS-1$ //$NON-NLS-2$
						}
						// Write the file to disk only if the LayerBuild was successfully added to the cache
						if (previousEntry == null) {
							// Updated entry was added to the cache.
							entry = updateEntry;
							entry.persist(mgr);
						}
						// If the key changed, then remove the entry under the old key.  Use a
						// delay to give other threads a chance to start using the new cache
						// key generator.  No need to update entry weight in map
						if (originalKey != null) {
							aggr.getExecutors().getScheduledExecutor().schedule(new Runnable() {
								public void run() {
									_layerBuilds.remove(originalKey, originalEntry);
								}
							}, LAYERBUILD_REMOVE_DELAY_SECONDS, TimeUnit.SECONDS);
						}
					} else {
						if (cacheInfoReport != null) {
							cacheInfoReport.add("update_weights_2"); //$NON-NLS-1$
						}
						_layerBuilds.replace(key, entry, entry);	// updates entry weight in map
						entry.persist(mgr);
					}
				}
			}
			result = setResponse(request, response, entry);
			// return the input stream to the LayerBuild
			if (log.isLoggable(Level.FINEST)) {
				log.finest(cacheInfoReport.toString() + "\n" + //$NON-NLS-1$
						"key:" + key +  //$NON-NLS-1$
						"\n" + entry.toString()); //$NON-NLS-1$
			}
			if (_isReportCacheInfo) {
				request.setAttribute(LAYERBUILDCACHEKEY_PROPNAME, key);
			}
			return result;
		} catch (IOException e) {
			_layerBuilds.remove(key, entry);
			throw e;
		} catch (RuntimeException e) {
			_layerBuilds.remove(key, entry);
			throw e;
		} finally {
			if (cacheKeyGenMutexAcquired) {
				_cacheKeyGenMutex.release();
			}
			if (_layerBuilds.isLayerEvicted()) {
				_layerBuilds.removeLayerFromCache(this);
			}
			// Help out the GC by clearing the module list
			if (moduleList != null) {
				request.removeAttribute(MODULE_FILES_PROPNAME);
				moduleList.clear();
			}
		}
	}
946577
@Override
    public InputStream getInputStream() throws IOException {
        if (!exists()) {
            throw new FileNotFoundException(getPath() + " (no such file or directory)");
        }
        if (Files.isDirectory(this.path)) {
            throw new FileNotFoundException(getPath() + " (is a directory)");
        }
        return Files.newInputStream(this.path);
    }
155344
public static InputStream getRequestInputStream(ExternalContext ec)
            throws IOException
    {
        RequestType type = getRequestType(ec);
        if (type.isRequestFromClient())
        {
            Object req = ec.getRequest();
            if (type.isPortlet())
            {
                return (InputStream) _runMethod(req, "getPortletInputStream");
            }
            else
            {
                return ((ServletRequest) ec.getRequest()).getInputStream();
            }
        }

        return null;
    }
276944
@Override
	public ServletInputStream getInputStream() {
		byte[] data = content == null ? new byte[0] : content;

		return new MockServletInputStream(new ByteArrayInputStream(data));
	}
668979
public File getOutputFile ()
  {
    File outputFile = null;
    if (this.outputDirectory != null && this.inputFile != null)
    {
      final String fileName = FileUtils.removeExtension (this.inputFile.getName ()) + ".jj";
      outputFile = new File (this.outputDirectory, fileName);
    }
    return outputFile;
  }
475277
public synchronized void setOutputStream(OutputStream out)
    {
        _reopen=isStarted() && out!=out;
        _filename=null;
        if (_buffer!=null)
            _buffer.resetWriter();
        _out=out;
    }
423938
public BufferedInputStream getInputStream() throws IORuntimeException {
		try {
			return new BufferedInputStream(new FileInputStream(this.file));
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
	}
1129101
public final ServletOutputStream getOutputStream() throws IOException {
        if (out == null) {
            OutputStream out = createOutputStream();
            this.out = out instanceof ServletOutputStream ? out : new OutputStreamAdapter(out);
        }
        else if (out instanceof PrintWriter) {
            throw new IllegalStateException("getWriter() already called.");
        }

        return (ServletOutputStream) out;
    }
178648
@Override
  public InputStream getInputStream()
    throws IOException
  {
    InputStream is = _is;
    _is = null;

    return is;
  }