/**
  * Helper method used when value to serialize is {@link Closeable} and its <code>close()</code>
  * method is to be called right after serialization has been called
  */
 private final void _writeCloseable(JsonGenerator jgen, Object value, SerializationConfig cfg)
     throws IOException, JsonGenerationException, JsonMappingException {
   Closeable toClose = (Closeable) value;
   try {
     if (_rootType == null) {
       _serializerProvider(cfg).serializeValue(jgen, value);
     } else {
       _serializerProvider(cfg).serializeValue(jgen, value, _rootType, _rootSerializer);
     }
     JsonGenerator tmpJgen = jgen;
     jgen = null;
     tmpJgen.close();
     Closeable tmpToClose = toClose;
     toClose = null;
     tmpToClose.close();
   } finally {
     /* Need to close both generator and value, as long as they haven't yet
      * been closed
      */
     if (jgen != null) {
       try {
         jgen.close();
       } catch (IOException ioe) {
       }
     }
     if (toClose != null) {
       try {
         toClose.close();
       } catch (IOException ioe) {
       }
     }
   }
 }
 /**
  * Helper method used when value to serialize is {@link Closeable} and its <code>close()</code>
  * method is to be called right after serialization has been called
  */
 private final void _writeCloseableValue(JsonGenerator jgen, Object value, SerializationConfig cfg)
     throws IOException, JsonGenerationException, JsonMappingException {
   Closeable toClose = (Closeable) value;
   try {
     if (_rootType == null) {
       _serializerProvider(cfg).serializeValue(jgen, value);
     } else {
       _serializerProvider(cfg).serializeValue(jgen, value, _rootType, _rootSerializer);
     }
     if (_config.isEnabled(SerializationFeature.FLUSH_AFTER_WRITE_VALUE)) {
       jgen.flush();
     }
     Closeable tmpToClose = toClose;
     toClose = null;
     tmpToClose.close();
   } finally {
     if (toClose != null) {
       try {
         toClose.close();
       } catch (IOException ioe) {
       }
     }
   }
 }