package com.google.enterprise.adaptor;

import java.io.IOException;
import java.io.OutputStream;
import java.util.Collections;
import java.util.Map;

/**
 * The document content transformer can modify the content of a document.
 *
 * @author Dominik Weidenfeld (dominik.weidenfeld@twt.de)
 */
public class DocumentContentTransformer extends OutputStream {

  protected final Map<String, String> config;
  protected final Metadata metadata;
  protected final String contentType;
  private OutputStream originalStream;

  /**
   * Constructs a document content transformer.
   *
   * @param config         the configuration for this instance
   *                       (could possibly be null or empty)
   * @param originalStream the original content stream
   * @param contentType    the content type of the stream
   *                       (could possibly be null or empty)
   * @param metadata       the metadata already collected for this document
   *                       (never null, but maybe empty)
   */
  public DocumentContentTransformer(final Map<String, String> config,
                                    final OutputStream originalStream, final String contentType,
                                    final Metadata metadata) {
    if (null == originalStream) {
      throw new NullPointerException();
    }
    this.config = Collections.unmodifiableMap(config);
    this.originalStream = originalStream;
    this.contentType = contentType;
    this.metadata = metadata;
  }

  @Override
  public void write(int b) throws IOException {
    originalStream.write(b);
  }

  @Override
  public void write(byte[] b) throws IOException {
    originalStream.write(b);
  }

  @Override
  public void write(byte[] b, int off, int len) throws IOException {
    originalStream.write(b, off, len);
  }

  @Override
  public void flush() throws IOException {
    originalStream.flush();
  }

  @Override
  public void close() throws IOException {
    originalStream.close();
  }
}

@@ -120,16 +120,42 @@
 ctions;%0A
+import java.util.HashMap;%0A
 import j
@@ -1393,15 +1393,44 @@
 Map(
+new HashMap%3CString, String%3E(
 config)
+)
 ;%0A  

copy config map, so it won/'t get unmodifiable