Merges multiple images into one multi-page TIFF image.

@param imageList a list of <code>IIOImage</code> objects
@param outputTiff the output TIFF file
@throws IOException
439097
public static void mergeTiff(List<IIOImage> imageList, File outputTiff) throws IOException {
        mergeTiff(imageList, outputTiff, null);
    }
70517
public void flush() throws IOException {
        String outputType = getOutputContentType();

        // Force transcoding, if no other filtering is done
        if (outputType != null && !outputType.equals(originalContentType)) {
            getImage();
        }

        if (image != null) {
            Iterator writers = ImageIO.getImageWritersByMIMEType(outputType);
            if (writers.hasNext()) {
                super.setContentType(outputType);
                OutputStream out = super.getOutputStream();
                try {
                    ImageWriter writer = (ImageWriter) writers.next();
                    try {
                        ImageWriteParam param = writer.getDefaultWriteParam();
    ///////////////////
    // POST-PROCESS
                        // For known formats that don't support transparency, convert to opaque
                        if (isNonAlphaFormat(outputType) && image.getColorModel().getTransparency() != Transparency.OPAQUE) {
                            image = ImageUtil.toBuffered(image, BufferedImage.TYPE_INT_RGB);
                        }

                        Float requestQuality = (Float) originalRequest.getAttribute(ImageServletResponse.ATTRIB_OUTPUT_QUALITY);

                        // The default JPEG quality is not good enough, so always adjust compression/quality
                        if ((requestQuality != null || "jpeg".equalsIgnoreCase(getFormatNameSafe(writer))) && param.canWriteCompressed()) {
                            // TODO: See http://blog.apokalyptik.com/2009/09/16/quality-time-with-your-jpegs/ for better adjusting the (default) JPEG quality
                            // OR: Use the metadata of the original image

                            param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);

                            // WORKAROUND: Known bug in GIFImageWriter in certain JDK versions, compression type is not set by default
                            if (param.getCompressionTypes() != null && param.getCompressionType() == null) {
                                param.setCompressionType(param.getCompressionTypes()[0]); // Just choose any, to keep param happy
                            }

                            param.setCompressionQuality(requestQuality != null ? requestQuality : 0.8f);
                        }

                        if ("gif".equalsIgnoreCase(getFormatNameSafe(writer)) && !(image.getColorModel() instanceof IndexColorModel) 
                                /*&& image.getColorModel().getTransparency() != Transparency.OPAQUE*/) {
                            // WORKAROUND: Bug in GIFImageWriter may throw NPE if transparent pixels
                            // See: http://bugs.sun.com/view_bug.do?bug_id=6287936
                            image = ImageUtil.createIndexed(
                                    ImageUtil.toBuffered(image), 256, null,
                                    (image.getColorModel().getTransparency() == Transparency.OPAQUE ? ImageUtil.TRANSPARENCY_OPAQUE : ImageUtil.TRANSPARENCY_BITMASK) | ImageUtil.DITHER_DIFFUSION_ALTSCANS
                            );
                        }
    //////////////////
                        ImageOutputStream stream = ImageIO.createImageOutputStream(out);

                        writer.setOutput(stream);
                        try {
                            writer.write(null, new IIOImage(image, null, null), param);
                        }
                        finally {
                            stream.close();
                        }
                    }
                    finally {
                        writer.dispose();
                    }
                }
                finally {
                    out.flush();
                }
            }
            else {
                context.log("ERROR: No writer for content-type: " + outputType);
                throw new IIOException("Unable to transcode image: No suitable image writer found (content-type: " + outputType + ").");
            }
        }
        else {
            super.setContentType(originalContentType);

            ServletOutputStream out = super.getOutputStream();

            try {
                if (bufferedOut != null) {
                    bufferedOut.writeTo(out);
                }
            }
            finally {
                out.flush();
            }
        }
    }
1046986
public static void flip(Image image, File outFile) throws IORuntimeException {
		write(flip(image), outFile);
	}
1151751
public void serialize(List<T> list, OutputStream os) throws IOException {
        JsonGenerator jsonGenerator = LoganSquare.JSON_FACTORY.createGenerator(os);
        serialize(list, jsonGenerator);
        jsonGenerator.close();
    }
680016
public static <T> List<T> mergeLists(List<T> list1, List<T> list2) {
        List<T> merged = new LinkedList<T>();
        if (list1 != null) {
            merged.addAll(list1);
        }
        if (list2 != null) {
            merged.addAll(list2);
        }
        return merged;
    }
799629
public static void writeFileList(Iterable<File> files, CharSink sink) throws IOException {
    writeUnixLines(FluentIterable.from(files)
        .transform(toAbsolutePathFunction()), sink);
  }
1356408
public <T> File writeLines(Collection<T> list, boolean isAppend) throws IORuntimeException {
		return writeLines(list, null, isAppend);
	}
1136882
public static void writeOut(BufferedImage image, OutputStream os, String format) throws IOException {
	ImageIO.write(image, format, os);

    }
917073
private void mergeFiles(List<File> inputFiles, OutputStream outputStream)
      throws IOException {
    long startTime = System.nanoTime();

    //Merge files
    for (File f : inputFiles) {
      if (f.exists()) {
        FileInputStream fileInputStream = new FileInputStream(f);
        BufferedInputStream bufferedInputStream = new BufferedInputStream(fileInputStream);
        try {
          LOGGER.log(Level.INFO, "Merging {0} size={1}", new Object[]{f.getName(), f.length()});

          byte[] buffer = new byte[8192];
          int length;
          while ((length = bufferedInputStream.read(buffer)) > 0) {
            outputStream.write(buffer, 0, length);
          }
        } finally {
          bufferedInputStream.close();
          fileInputStream.close();
        }
      } else {
        LOGGER.log(Level.INFO, "Skip merging file {0} because it doesn't exist", f.getName());
      }
    }

    LOGGER.log(Level.INFO, "Time to merge {0} s", ((System.nanoTime() - startTime) / 1000000000.0));
  }
1275441
def addIVMInputs(imageObjectList,ivmlist):
    
    if ivmlist is None:
        return

    for img,ivmname in zip(imageObjectList,ivmlist):
        img.updateIVMName(ivmname)
424419
public static void appendImage(String imagePath, int pictureType, int width, int height, ParagraphAlignment
            alignment) throws IOException, InvalidFormatException {
        appendImage(getNewRun(alignment), imagePath, pictureType, width, height);
    }
45260
private void mergeFiles(@NonNull File mergedFile) throws IOException {

        Context context = appContextRef.get();

        if (context != null) {

            FileWriter fw;
            BufferedWriter bw;
            fw = new FileWriter(mergedFile, true);
            bw = new BufferedWriter(fw);

            File dir = context.getFilesDir();
            for (int i = 1; i <= maxFiles; i++) {

                File file = new File(dir, name(i));
                if (file.exists()) {

                    FileInputStream fis;
                    try {

                        fis = new FileInputStream(file);
                        BufferedReader br = new BufferedReader(new InputStreamReader(fis));
                        //noinspection TryFinallyCanBeTryWithResources
                        try {
                            String aLine;
                            while ((aLine = br.readLine()) != null) {
                                bw.write(aLine);
                                bw.newLine();
                            }
                        } finally {
                            br.close();
                        }
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }

            bw.close();
        }
    }
618179
public static String[] merge(final String[] input, final String[] list) {
        final List<String> v = new ArrayList<String>(Arrays.asList(list));
        for (final String anInput : input) {
            if ((null != anInput) && !v.contains(anInput)) {
                v.add(anInput);
            }
        }
        return v.toArray(new String[v.size()]);
    }
864473
@Override
   public void loadTiff(URL tiff, ImageProcessor imageProcessor, int... pages) throws VectorPrintException {
      try {
         if (log.isLoggable(Level.FINE)) {
            log.fine(String.format("loading tiff from %s", String.valueOf(tiff)));
         }
         if ("file".equals(tiff.getProtocol())) {
            loadTiff(new File(tiff.getFile()), imageProcessor, pages);
         } else {
            loadTiff(tiff.openStream(), imageProcessor, pages);
         }
      } catch (IOException ex) {
         throw new VectorPrintException(String.format("unable to load image %s", tiff.toString()), ex);
      }
   }
977678
public static ImageOutputStream getImageOutputStream(File outFile) throws IORuntimeException {
		try {
			return ImageIO.createImageOutputStream(outFile);
		} catch (IOException e) {
			throw new IORuntimeException(e);
		}
	}
491797
@Override
  public void merge(MergeState mergeState) throws IOException {
    final List<Fields> fields = new ArrayList<>();
    final List<ReaderSlice> slices = new ArrayList<>();

    int docBase = 0;

    for (int readerIndex = 0; readerIndex < mergeState.fieldsProducers.length; readerIndex++) {
      final FieldsProducer f = mergeState.fieldsProducers[readerIndex];

      final int maxDoc = mergeState.maxDocs[readerIndex];
      f.checkIntegrity();
      slices.add(new ReaderSlice(docBase, maxDoc, readerIndex));
      fields.add(f);
      docBase += maxDoc;
    }

    Fields mergedFields = new MappedMultiFields(mergeState,
        new MultiFields(fields.toArray(Fields.EMPTY_ARRAY),
            slices.toArray(ReaderSlice.EMPTY_ARRAY)));
    write(mergedFields);
  }
4103
public static <E extends Comparable<E>> void sort(List<E> list) {
        Merge.sort(list, 0, list.size()-1, false);
    }