Serialize a list of objects to an OutputStream.

@param list The list of objects to serialize.
@param os The OutputStream to which the list should be serialized
@param jsonObjectClass The @JsonObject class of the list elements
338795
public static <E> void serialize(List<E> list, OutputStream os, Class<E> jsonObjectClass) throws IOException {
        mapperFor(jsonObjectClass).serialize(list, os);
    }
964953
public void dump(final OutputStream os)
            throws IOException {
        final byte [] outputBuffer = new byte [16*1024];
        int read = outputBuffer.length;
        while ((read = read(outputBuffer, 0, outputBuffer.length)) != -1) {
            os.write(outputBuffer, 0, read);
        }
        os.flush();
    }
1323790
@SuppressWarnings("unchecked")
  private static List<String> toList(Object object) {
    List<String> list = new ArrayList<String>();

    if (object == null || object == JSONObject.NULL) {
      return null;
    }

    if (object instanceof List) {
      return ((List<String>) object);
    } else if (object instanceof JSONArray) {
      for (int i = 0; i < ((JSONArray) object).length(); i++) {
        try {
          list.add(String.valueOf((((JSONArray) object).get(i))));
        } catch (JSONException ex) {
          //issue converting the list. return null
          return null;
        }
      }
    } else {
      list.add(object.toString());
    }

    return list;
  }
1016935
public static void serialize(Element element, OutputStream os) {
        Source source = new DOMSource(element);
        serialize(source, os);
    }
1012745
protected void copyStreams(InputStream is, OutputStream os) throws IOException {
        byte[] buffer = new byte[1024];
        try {
            int read;
            while ((read = is.read(buffer)) != -1) {
                os.write(buffer, 0, read);
                buffer = new byte[1024];
            }
        } finally {
            if (null != os)
                os.close();
            if (null != is)
                is.close();
        }
    }
548616
@GwtIncompatible("ObjectOutputStream")
  public void serialize(OutputStream objectOutputStream) throws IOException {
    new java.io.ObjectOutputStream(objectOutputStream).writeObject(this);
  }
142136
public final void serialize(OutputStream out) throws IOException {
        out.write(Jackson.toJsonString(this).getBytes(UTF8));
        out.flush();
    }
297943
public static void writeGzipObjectToStream(final Object o, OutputStream out) {
    out = new BufferedOutputStream(out);
    try {
      out = new GZIPOutputStream(out, true);
      final ObjectOutputStream oos = new ObjectOutputStream(out);
      oos.writeObject(o);
      oos.flush();
    } catch (final IOException e) {
      e.printStackTrace();
    }
  }
386941
public static <E> List<E> parseList(InputStream is, Class<E> jsonObjectClass) throws IOException {
        return mapperFor(jsonObjectClass).parseList(is);
    }
417233
public static <T> JSONArray listToJSONArray(final List<T> list) {
        final JSONArray ret = new JSONArray();

        if (null == list) {
            return ret;
        }

        for (final T object : list) {
            ret.put(object);
        }

        return ret;
    }
87265
@SuppressWarnings("unchecked")
    public static <E> void serialize(E object, OutputStream os) throws IOException {
        mapperFor((Class<E>)object.getClass()).serialize(object, os);
    }
24832
public void init(OutputStream os)
    {
        this.os = os;

        _refs = null;

        if (_serializerFactory == null)
            _serializerFactory = new SerializerFactory();
    }
660997
public void storeToJSON(final OutputStream os) throws IOException {
		lock.readLock().lock();
		try {
			final JsonFactory f = new JsonFactory();
			final JsonGenerator generator = f.createGenerator(os, JsonEncoding.UTF8);
//			generator.configure(Feature.QUOTE_FIELD_NAMES, false);
			generator.useDefaultPrettyPrinter();

			generator.writeStartObject();
			writeJsonOrYaml(generator, getTreeMap());
			generator.writeEndObject();
			generator.flush();
		} finally {
			lock.readLock().unlock();
		}
	}
859593
public static int serialize(OutputStream stream, Object obj) {
        ObjectMapper mapper = createMapperWithJaxbAnnotationInspector();

        try (DataOutputStream data = new DataOutputStream(stream);
             OutputStreamWriter writer = new OutputStreamWriter(data, StandardCharsets.UTF_8)) {
            mapper.writerWithDefaultPrettyPrinter().writeValue(writer, obj);
            return data.size();
        } catch (IOException e) {
            throw new ReportGenerationException(e);
        }
    }
929183
private void writeObject(final ObjectOutputStream out) throws IOException {
        out.defaultWriteObject();
        out.writeInt(table.length);

        // Have to use null-terminated list because size might shrink
        // during iteration

        for (final Object o : entrySet()) {
            final Map.Entry entry = (Map.Entry) o;
            out.writeObject(entry.getKey());
            out.writeObject(entry.getValue());
        }
        out.writeObject(null);
    }
1239902
public void write(Service model, OutputStream os) throws IOException {
    objectMapper.writerWithDefaultPrettyPrinter().writeValue(os, model);
  }
848068
public static void copy(InputStream is, OutputStream os) throws IOException {

		Asserts.notNullParameter("is", is);
		Asserts.notNullParameter("os", os);
		
		try {
			byte[] buf = new byte[1024];
			int len = 0;
			
			while((len = is.read(buf)) > 0) {
				os.write(buf, 0, len);
			}
		
		} finally {
			if(os != null) {
				try {
					os.close();
				} catch (IOException e) {
					// ignore
				}
			}
			if(is != null) {
				try {
					is.close();
				} catch (IOException e) {
					// ignore
				}
			}
		}
	}