Transcode file to JPEG.

@param file Output filename
@param width Width
@param height Height
@throws IOException On write errors
@throws TranscoderException On input/parsing errors.
165766
public void saveAsJPEG(File file, int width, int height) throws IOException, TranscoderException {
    saveAsJPEG(file, width, height, DEFAULT_QUALITY);
  }
900830
private static void writeToFile(InputStream in, File file) {
    try {
      OutputStream out = new FileOutputStream(file);
      byte[] buf = new byte[1024];
      int len;
      while ((len = in.read(buf)) > 0) {
        out.write(buf, 0, len);
      }
      out.close();
      in.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
493819
public void writeToFile(File file) {
        try {
            try (OutputStream os = new FileOutputStream(file)) {
                InputStreams.transferTo(body(), os);
            }
        } catch (IOException e) {
            throw new RequestsException(e);
        } finally {
            close();
        }
    }
999582
private static void writeHeader(Path file) throws IOException {
        try (FileChannel fout = FileChannel.open(file, StandardOpenOption.WRITE)) {

            long size = fout.size();
            int sampleSize = (int) size - 44;

            if (logger.isInfoEnabled()) {
                logger.info("Size  " + sampleSize + " of recording file " + file);
            }

            ByteBuffer headerBuffer = ByteBuffer.allocateDirect(44);
            headerBuffer.clear();
            // RIFF
            headerBuffer.put((byte) 0x52);
            headerBuffer.put((byte) 0x49);
            headerBuffer.put((byte) 0x46);
            headerBuffer.put((byte) 0x46);

            int length = sampleSize + 36;

            // Length
            headerBuffer.put((byte) (length));
            headerBuffer.put((byte) (length >> 8));
            headerBuffer.put((byte) (length >> 16));
            headerBuffer.put((byte) (length >> 24));

            // WAVE
            headerBuffer.put((byte) 0x57);
            headerBuffer.put((byte) 0x41);
            headerBuffer.put((byte) 0x56);
            headerBuffer.put((byte) 0x45);

            // fmt
            headerBuffer.put((byte) 0x66);
            headerBuffer.put((byte) 0x6d);
            headerBuffer.put((byte) 0x74);
            headerBuffer.put((byte) 0x20);

            headerBuffer.put((byte) 0x10);
            headerBuffer.put((byte) 0x00);
            headerBuffer.put((byte) 0x00);
            headerBuffer.put((byte) 0x00);

            // format - PCM
            headerBuffer.put((byte) 0x01);
            headerBuffer.put((byte) 0x00);

            // format - MONO
            headerBuffer.put((byte) 0x01);
            headerBuffer.put((byte) 0x00);

            // sample rate:8000
            headerBuffer.put((byte) 0x40);
            headerBuffer.put((byte) 0x1F);
            headerBuffer.put((byte) 0x00);
            headerBuffer.put((byte) 0x00);

            // byte rate
            headerBuffer.put((byte) 0x80);
            headerBuffer.put((byte) 0x3E);
            headerBuffer.put((byte) 0x00);
            headerBuffer.put((byte) 0x00);

            // Block align
            headerBuffer.put((byte) 0x02);
            headerBuffer.put((byte) 0x00);

            // Bits per sample: 16
            headerBuffer.put((byte) 0x10);
            headerBuffer.put((byte) 0x00);

            // "data"
            headerBuffer.put((byte) 0x64);
            headerBuffer.put((byte) 0x61);
            headerBuffer.put((byte) 0x74);
            headerBuffer.put((byte) 0x61);

            // len
            headerBuffer.put((byte) (sampleSize));
            headerBuffer.put((byte) (sampleSize >> 8));
            headerBuffer.put((byte) (sampleSize >> 16));
            headerBuffer.put((byte) (sampleSize >> 24));

            headerBuffer.rewind();

            // lets write header
            fout.position(0);
            fout.write(headerBuffer);
        }
    }
673039
public static void write(byte[] bytes,File file) throws IOException {
        BufferedOutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
        outputStream.write(bytes);
        outputStream.close();
    }
118250
public static void renderFile(File file, String responseFileName, int bufferSize) {
		new FileView(file, responseFileName, bufferSize).render();
	
	}
75438
public BufferedImage createImage (int width, int height, int trans)
    {
        // DEBUG: override transparency for the moment on all images
        trans = Transparency.TRANSLUCENT;
        if (_gc != null) {
            return _gc.createCompatibleImage(width, height, trans);
        } else {
            // if we're running in headless mode, do everything in 24-bit
            return new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
        }
    }
1359561
public static void printScreen(int x, int y, int width, int height, String format,File file)
	  {
	     try
	     {
		  if(robot == null)
			  robot = new Robot();
		     
		  synchronized (robot)
		  {
		     Rectangle rect = new Rectangle(x,y,width,height);
		     
		     BufferedImage image = robot.createScreenCapture(rect);
		     ImageIO.write(image, format, file);
		  }
	     } 
	     catch (Exception e)
	     {
		  throw new SystemException(Debugger.stackTrace(e));
		}
	  }
1221021
protected byte[] fileToByteArray(File file) throws IOException
   {
      FileInputStream in = null;

      try
      {
         if (channel == null || !channel.isOpen())
         {
            in = PrivilegedFileHelper.fileInputStream(file);
            channel = in.getChannel();
         }

         ByteBuffer bb = ByteBuffer.allocate((int)channel.size());
         channel.read(bb);
         if (bb.hasArray())
         {
            return bb.array();
         }
         else
         {
            // impossible code in most cases, as we use heap backed buffer
            byte[] tmpb = new byte[bb.capacity()];
            bb.get(tmpb);
            return tmpb;
         }
      }
      finally
      {
         if (in != null)
         {
            in.close();
            if (channel != null)
            {
               channel.close();
            }
         }
      }
   }
366833
public static void write(String string, File file) throws IOException {
        try (Writer w = new OutputStreamWriter(new FileOutputStream(file), ENCODING_UTF_8)) {
            w.write(string);
        }
    }
521937
@SneakyThrows
    public static void generateQRCode(final OutputStream stream, final String key,
                                      final int width, final int height) {
        val hintMap = new EnumMap<EncodeHintType, Object>(EncodeHintType.class);
        hintMap.put(EncodeHintType.CHARACTER_SET, StandardCharsets.UTF_8.name());
        hintMap.put(EncodeHintType.MARGIN, 2);
        hintMap.put(EncodeHintType.ERROR_CORRECTION, ErrorCorrectionLevel.L);

        val qrCodeWriter = new QRCodeWriter();
        val byteMatrix = qrCodeWriter.encode(key, BarcodeFormat.QR_CODE, width, height, hintMap);
        val byteMatrixWidth = byteMatrix.getWidth();
        val image = new BufferedImage(byteMatrixWidth, byteMatrixWidth, BufferedImage.TYPE_INT_RGB);
        image.createGraphics();

        @Cleanup("dispose")
        val graphics = (Graphics2D) image.getGraphics();

        graphics.setColor(Color.WHITE);
        graphics.fillRect(0, 0, byteMatrixWidth, byteMatrixWidth);
        graphics.setColor(Color.BLACK);

        IntStream.range(0, byteMatrixWidth)
            .forEach(i -> IntStream.range(0, byteMatrixWidth)
                .filter(j -> byteMatrix.get(i, j))
                .forEach(j -> graphics.fillRect(i, j, 1, 1)));

        ImageIO.write(image, "png", stream);
    }
12855
public void writeToFile(StringBuffer content, String filename, String encoding) throws NoSuchPathException, IOException{
		try {
			OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(filename), encoding);
			writer.write(content.toString(), 0, content.length());
			writer.flush();
			writer.close();
		} catch (FileNotFoundException e) {
			throw new NoSuchPathException(e);
		}
	}
459469
@SuppressWarnings("resource")
    public static byte[] readFile(File file) throws IOException {

        // create input and output stream
        FileInputStream in = new FileInputStream(file);

        // read the content
        return readFully(in, (int)file.length());
    }
53859
public static OutputStream outputStream(File file) {
        try {
            return new FileOutputStream(file);
        } catch (FileNotFoundException e) {
            throw E.ioException(e);
        }
    }
595354
public static void writeFile(byte[] content,File file) throws IOException
    {
        OutputStream outputStream=null;
        try
        {
            //create output stream to file
            outputStream=new FileOutputStream(file);
            
            //write to file
            outputStream.write(content);
        }
        finally
        {
            //close writer
            IOHelper.closeResource(outputStream);
        }
    }
183980
public static void write(final CharSequence data, final File file) throws IOException {
		Validate.notNull(file);
		Validate.notNull(data);

		try (BufferedWriter writer = Files.newBufferedWriter(file.toPath(), Charsets.UTF_8)) {
			writer.append(data);
		}
	}
883440
public static byte[] copyToByteArray(File in) throws IOException {
        assert in != null : "No input File specified";

        return copyToByteArray(new BufferedInputStream(new FileInputStream(in)));
    }