@@ -474,53 +474,43 @@ public static Reader getReader(
474474 final org .restlet .representation .WriterRepresentation representation )
475475 throws IOException {
476476 Reader result = null ;
477- if (Edition .CURRENT != Edition .GAE ) {
478- // [ifndef gae]
479- final java .io .PipedWriter pipedWriter = new java .io .PipedWriter ();
480-
481- @ SuppressWarnings ("resource" )
482- java .io .PipedReader pipedReader = new java .io .PipedReader (
483- pipedWriter );
484-
485- // Gets a thread that will handle the task of continuously
486- // writing the representation into the input side of the pipe
487- Runnable task = new org .restlet .engine .util .ContextualRunnable () {
488- public void run () {
477+ final java .io .PipedWriter pipedWriter = new java .io .PipedWriter ();
478+
479+ @ SuppressWarnings ("resource" )
480+ java .io .PipedReader pipedReader = new java .io .PipedReader (pipedWriter );
481+
482+ // Gets a thread that will handle the task of continuously
483+ // writing the representation into the input side of the pipe
484+ Runnable task = new org .restlet .engine .util .ContextualRunnable () {
485+ public void run () {
486+ try {
487+ representation .write (pipedWriter );
488+ pipedWriter .flush ();
489+ } catch (IOException ioe ) {
490+ Context .getCurrentLogger ().log (Level .WARNING ,
491+ "Error while writing to the piped reader." , ioe );
492+ } finally {
489493 try {
490- representation .write (pipedWriter );
491- pipedWriter .flush ();
492- } catch (IOException ioe ) {
493- Context .getCurrentLogger ()
494- .log (Level .WARNING ,
495- "Error while writing to the piped reader." ,
496- ioe );
497- } finally {
498- try {
499- pipedWriter .close ();
500- } catch (IOException ioe2 ) {
501- Context .getCurrentLogger ().log (Level .WARNING ,
502- "Error while closing the pipe." , ioe2 );
503- }
494+ pipedWriter .close ();
495+ } catch (IOException ioe2 ) {
496+ Context .getCurrentLogger ().log (Level .WARNING ,
497+ "Error while closing the pipe." , ioe2 );
504498 }
505499 }
506- };
507-
508- org .restlet .Context context = org .restlet .Context .getCurrent ();
509-
510- if (context != null && context .getExecutorService () != null ) {
511- context .getExecutorService ().execute (task );
512- } else {
513- Engine .createThreadWithLocalVariables (task , "Restlet-IoUtils" )
514- .start ();
515500 }
501+ };
516502
517- result = pipedReader ;
518- // [enddef]
503+ org .restlet .Context context = org .restlet .Context .getCurrent ();
504+
505+ if (context != null && context .getExecutorService () != null ) {
506+ context .getExecutorService ().execute (task );
519507 } else {
520- Context .getCurrentLogger ()
521- .log (Level .WARNING ,
522- "The GAE edition is unable to return a reader for a writer representation." );
508+ Engine .createThreadWithLocalVariables (task , "Restlet-IoUtils" )
509+ .start ();
523510 }
511+
512+ result = pipedReader ;
513+
524514 return result ;
525515
526516 }
@@ -597,55 +587,46 @@ public static InputStream getStream(Reader reader, CharacterSet characterSet) {
597587 public static InputStream getStream (final Representation representation ) {
598588 InputStream result = null ;
599589
600- if (Edition .CURRENT != Edition .GAE ) {
601- // [ifndef gae]
602- if (representation == null ) {
603- return null ;
604- }
605-
606- final PipeStream pipe = new PipeStream ();
607- final java .io .OutputStream os = pipe .getOutputStream ();
590+ if (representation == null ) {
591+ return null ;
592+ }
608593
609- // Creates a thread that will handle the task of continuously
610- // writing the representation into the input side of the pipe
611- Runnable task = new org .restlet .engine .util .ContextualRunnable () {
612- public void run () {
594+ final PipeStream pipe = new PipeStream ();
595+ final java .io .OutputStream os = pipe .getOutputStream ();
596+
597+ // Creates a thread that will handle the task of continuously
598+ // writing the representation into the input side of the pipe
599+ Runnable task = new org .restlet .engine .util .ContextualRunnable () {
600+ public void run () {
601+ try {
602+ representation .write (os );
603+ os .flush ();
604+ } catch (IOException ioe ) {
605+ Context .getCurrentLogger ().log (Level .WARNING ,
606+ "Error while writing to the piped input stream." ,
607+ ioe );
608+ } finally {
613609 try {
614- representation .write (os );
615- os .flush ();
616- } catch (IOException ioe ) {
617- Context .getCurrentLogger ()
618- .log (Level .WARNING ,
619- "Error while writing to the piped input stream." ,
620- ioe );
621- } finally {
622- try {
623- os .close ();
624- } catch (IOException ioe2 ) {
625- Context .getCurrentLogger ().log (Level .WARNING ,
626- "Error while closing the pipe." , ioe2 );
627- }
610+ os .close ();
611+ } catch (IOException ioe2 ) {
612+ Context .getCurrentLogger ().log (Level .WARNING ,
613+ "Error while closing the pipe." , ioe2 );
628614 }
629615 }
630- };
631-
632- org .restlet .Context context = org .restlet .Context .getCurrent ();
633-
634- if (context != null && context .getExecutorService () != null ) {
635- context .getExecutorService ().execute (task );
636- } else {
637- Engine .createThreadWithLocalVariables (task , "Restlet-IoUtils" )
638- .start ();
639616 }
617+ };
640618
641- result = pipe .getInputStream ();
642- // [enddef]
619+ org .restlet .Context context = org .restlet .Context .getCurrent ();
620+
621+ if (context != null && context .getExecutorService () != null ) {
622+ context .getExecutorService ().execute (task );
643623 } else {
644- Context .getCurrentLogger ()
645- .log (Level .WARNING ,
646- "The GAE edition is unable to get an InputStream out of an OutputRepresentation." );
624+ Engine .createThreadWithLocalVariables (task , "Restlet-IoUtils" )
625+ .start ();
647626 }
648627
628+ result = pipe .getInputStream ();
629+
649630 return result ;
650631 }
651632
0 commit comments