wro4j-extensions/src/main/java/ro/isdc/wro/extensions/processor/js/GoogleClosureCompressorProcessor.java
@Override
  public void process(final Resource resource, final Reader reader, final Writer writer)
      throws IOException {
    final String content = IOUtils.toString(reader);
    final CompilerOptions compilerOptions = optionsPool.getObject();
    final Compiler compiler = newCompiler(compilerOptions);
    try {
      final String fileName = resource == null ? "wro4j-processed-file.js" : resource.getUri();
      final SourceFile[] input = new SourceFile[] {
        SourceFile.fromInputStream(fileName, new ByteArrayInputStream(content.getBytes(getEncoding())))
      };
      SourceFile[] externs = getExterns(resource);
      if (externs == null) {
        // fallback to empty array when null is provided.
        externs = new SourceFile[] {};
      }
      Result result = null;
      result = compiler.compile(Arrays.asList(externs), Arrays.asList(input), compilerOptions);
      if (result.success) {
        writer.write(compiler.toSource());
      } else {
        throw new WroRuntimeException("Compilation has errors: " + Arrays.asList(result.errors));
      }
    } catch (final Exception e) {
      onException(e);
    } finally {
      reader.close();
      writer.close();
      optionsPool.returnObject(compilerOptions);
    }
  }
@Override
  public void process(final Resource resource, final Reader reader, final Writer writer)
      throws IOException {
    final String content = IOUtils.toString(reader);
    final CompilerOptions compilerOptions = optionsPool.getObject();
    final Compiler compiler = newCompiler(compilerOptions);
    try {
      final String fileName = resource == null ? "wro4j-processed-file.js" : resource.getUri();
      final SourceFile[] input = new SourceFile[] {
        SourceFile.fromInputStream(fileName, new ByteArrayInputStream(content.getBytes(getEncoding())))
      };
      SourceFile[] externs = getExterns(resource);
      if (externs == null) {
        // fallback to empty array when null is provided.
        externs = new SourceFile[] {};
      }
      Result result = null;
      result = compiler.compile(Arrays.asList(externs), Arrays.asList(input), compilerOptions);
      if (result.success) {
        writer.write(compiler.toSource());
      } else {
        throw new WroRuntimeException("Compilation has errors: " + Arrays.asList(result.errors));
      }
    } catch (final Exception e) {
      onException(e);
    } finally {
      reader.close();
      writer.close();
      optionsPool.returnObject(compilerOptions);
    }
  }
@ Override public void process ( final Resource resource , final Reader reader , final Writer writer ) throws IOException { final String content = IOUtils . toString ( reader ) ; final CompilerOptions compilerOptions = optionsPool . getObject ( ) ; final Compiler compiler = newCompiler ( compilerOptions ) ; try { final String fileName = resource == null ? "wro4j-processed-file.js" : resource . getUri ( ) ; final SourceFile [ ] input = new SourceFile [ ] { SourceFile . fromInputStream ( fileName , new ByteArrayInputStream ( content . getBytes ( getEncoding ( ) ) ) ) } ; SourceFile [ ] externs = getExterns ( resource ) ; if ( externs == null ) { // fallback to empty array when null is provided.
 externs = new SourceFile [ ] { } ; } Result result = null ; result = compiler . compile ( Arrays . asList ( externs ) , Arrays . asList ( input ) , compilerOptions ) ; if ( result . success ) { writer . write ( compiler . toSource ( ) ) ; } else { throw new WroRuntimeException ( "Compilation has errors: " + Arrays . asList ( result . errors ) ) ; } } catch ( final Exception e ) { onException ( e ) ; } finally { reader . close ( ) ; writer . close ( ) ; optionsPool . returnObject ( compilerOptions ) ; } }
{@inheritDoc}
{