Java Examples for java.io.OutputStream

The following java examples will help you to understand the usage of java.io.OutputStream. These source code samples are taken from different open source projects.

Example 1
Project: oobd-master  File: MacDataGenerator.java View source code
public MacData build(char[] password, byte[] data) throws PKCSException {
    MacCalculator macCalculator = builder.build(password);
    AlgorithmIdentifier algId = macCalculator.getAlgorithmIdentifier();
    OutputStream out = macCalculator.getOutputStream();
    try {
        out.write(data);
        out.close();
    } catch (IOException e) {
        throw new PKCSException("unable to process data: " + e.getMessage(), e);
    }
    DigestInfo dInfo = new DigestInfo(builder.getDigestAlgorithmIdentifier(), macCalculator.getMac());
    PKCS12PBEParams params = PKCS12PBEParams.getInstance(algId.getParameters());
    return new MacData(dInfo, params.getIV(), params.getIterations().intValue());
}
Example 2
Project: ARKOST-master  File: Utils.java View source code
public static void CopyStream(InputStream is, OutputStream os) {
    final int buffer_size = 1024;
    try {
        byte[] bytes = new byte[buffer_size];
        for (; ; ) {
            int count = is.read(bytes, 0, buffer_size);
            if (count == -1)
                break;
            os.write(bytes, 0, count);
        }
    } catch (Exception ex) {
    }
}
Example 3
Project: SecurePhoto-master  File: Utils.java View source code
public static void CopyStream(InputStream is, OutputStream os) {
    final int buffer_size = 1024;
    try {
        byte[] bytes = new byte[buffer_size];
        for (; ; ) {
            int count = is.read(bytes, 0, buffer_size);
            if (count == -1)
                break;
            os.write(bytes, 0, count);
        }
    } catch (Exception ex) {
    }
}
Example 4
Project: OrderNowAndroid-master  File: Utils.java View source code
public static void CopyStream(InputStream is, OutputStream os) {
    final int buffer_size = 1024;
    try {
        byte[] bytes = new byte[buffer_size];
        for (; ; ) {
            int count = is.read(bytes, 0, buffer_size);
            if (count == -1)
                break;
            os.write(bytes, 0, count);
        }
    } catch (Exception ex) {
    }
}
Example 5
Project: korsakow-editor-master  File: SrtEncoder.java View source code
public void encode(OutputStream output) throws IOException {
    Collections.sort(subtitles);
    PrintWriter writer = new PrintWriter(output);
    int counter = 0;
    for (ISubtitle subtitle : subtitles) {
        writer.println(counter);
        writer.print(formatTime(subtitle.getStartTime()));
        writer.print(" --> ");
        writer.print(formatTime(subtitle.getEndTime()));
        writer.println();
        writer.println(subtitle.getText());
        writer.println();
    }
    output.close();
}
Example 6
Project: ocr-tools-master  File: Merger.java View source code
public void mergeBuffered(List<InputStream> inputs, OutputStream output) throws IOException {
    BufferedOutputStream bufferedOutput = new BufferedOutputStream(output, 8 * 1024);
    try {
        merge(inputs, bufferedOutput);
    } finally {
        bufferedOutput.flush();
        bufferedOutput.close();
    }
}
Example 7
Project: openjdk-master  File: DemultiplexInput.java View source code
@Override
public void run() {
    try {
        while (true) {
            int nameLen = delegate.read();
            if (nameLen == (-1)) {
                break;
            }
            byte[] name = new byte[nameLen];
            DemultiplexInput.this.delegate.readFully(name);
            int dataLen = delegate.read();
            byte[] data = new byte[dataLen];
            DemultiplexInput.this.delegate.readFully(data);
            String chan = new String(name, "UTF-8");
            OutputStream out = io.get(chan);
            if (out == null) {
                debug("Unexpected channel name: %s", chan);
            } else {
                out.write(data);
            }
        }
    } catch (IOException ex) {
        debug(ex, "Failed reading output");
    } finally {
        for (OutputStream out : closeList) {
            try {
                out.close();
            } catch (IOException ex) {
                debug(ex, "Failed reading output");
            }
        }
    }
}
Example 8
Project: trie4j-master  File: CreateTail.java View source code
public static void main(String[] args) throws Exception {
    TailPatriciaTrie trie = new TailPatriciaTrie();
    for (String s : new WikipediaTitles("data/jawiki-20120220-all-titles-in-ns0.gz")) {
        trie.insert(s);
    }
    ConcatTailArrayBuilder ta = new ConcatTailArrayBuilder(trie.size());
    new TailLOUDSTrie(trie, ta);
    OutputStream os = new FileOutputStream("data/jawiki-20120220-tail");
    try {
    /*			CharSequence seq = ta.build().getTails();
			byte[] bytes = seq.toString().getBytes("UTF16");
			System.out.println(seq.length() + "chars.");
			System.out.println(bytes.length + "bytes.");
			os.write(bytes);
*/
    } finally {
        os.close();
    }
}
Example 9
Project: TestingStuff-master  File: ImageUtils.java View source code
public static void copyStream(InputStream is, OutputStream os) {
    final int buffer_size = 1024;
    try {
        byte[] bytes = new byte[buffer_size];
        for (; ; ) {
            int count = is.read(bytes, 0, buffer_size);
            if (count == -1)
                break;
            os.write(bytes, 0, count);
        }
    } catch (Exception ex) {
    }
}
Example 10
Project: download-manager-master  File: IOHelpers.java View source code
/**
     * Closes an outputStream and the FileDescriptor associated with it after ensuring all data as been written to disk.
     */
static void closeAfterWrite(OutputStream out, FileDescriptor outFd) {
    try {
        if (out != null) {
            out.flush();
        }
        if (outFd != null) {
            outFd.sync();
        }
    } catch (IOException e) {
        LLog.e("Fail sync");
    } finally {
        closeQuietly(out);
    }
}
Example 11
Project: O2OMobile_Android-master  File: Transmitter.java View source code
public static void transmit(Command c, Map h, String b, java.io.OutputStream out) throws IOException {
    StringBuffer message = new StringBuffer(c.toString());
    message.append("\n");
    if (h != null) {
        for (Iterator keys = h.keySet().iterator(); keys.hasNext(); ) {
            String key = (String) keys.next();
            String value = (String) h.get(key);
            message.append(key);
            message.append(":");
            message.append(value);
            message.append("\n");
        }
    }
    message.append("\n");
    if (b != null)
        message.append(b);
    message.append("\000");
    out.write(message.toString().getBytes(Command.ENCODING));
}
Example 12
Project: turmeric-eclipse-master  File: TestFreeMarkerUtil.java View source code
/**
	 * Test method for [email protected] [email protected]rate(java.util.Map, java.lang.Object, java.lang.String, java.io.OutputStream)}.
	 * @throws TemplateException 
	 * @throws IOException 
	 */
@Test
public void testGenerate() throws IOException, TemplateException {
    OutputStream output = null;
    InputStream input = null;
    try {
        output = new ByteArrayOutputStream();
        Map<String, String> data = new ConcurrentHashMap<String, String>();
        data.put("serviceName", "NikonLensService");
        String templateFileName = "geronimo-web.xml.ftl";
        URL templateParentFolder = TestFreeMarkerUtil.class.getResource(templateFileName);
        Assert.assertNotNull(templateParentFolder);
        FreeMarkerUtil.generate(data, templateParentFolder, templateFileName, output);
        System.out.println(output.toString());
        input = TestFreeMarkerUtil.class.getResourceAsStream("geronimo-web.xml");
        Assert.assertNotNull(templateParentFolder);
        String expected = IOUtils.toString(input);
        Assert.assertEquals(expected, output.toString());
    } finally {
        IOUtils.closeQuietly(output);
        IOUtils.closeQuietly(input);
    }
}
Example 13
Project: GeoGig-master  File: WriterRepresentation.java View source code
@Override
public void write(OutputStream outputStream) throws IOException {
    Writer writer = null;
    if (getCharacterSet() != null) {
        writer = new OutputStreamWriter(outputStream, getCharacterSet().getName());
    } else {
        // Use the default HTTP character set
        writer = new OutputStreamWriter(outputStream, CharacterSet.UTF_8.getName());
    }
    write(writer);
    writer.flush();
}
Example 14
Project: molgenis-master  File: LogoController.java View source code
/**
	 * Get a file from the logo subdirectory of the filestore
	 *
	 * @param out
	 * @param name
	 * @param extension
	 * @param response
	 * @throws IOException
	 */
@RequestMapping("/logo/{name}.{extension}")
public void getLogo(OutputStream out, @PathVariable("name") String name, @PathVariable("extension") String extension, HttpServletResponse response) throws IOException {
    File f = fileStore.getFile("/logo/" + name + "." + extension);
    if (!f.exists()) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }
    // Try to get contenttype from file
    String contentType = URLConnection.guessContentTypeFromName(f.getName());
    if (contentType != null) {
        response.setContentType(contentType);
    }
    FileCopyUtils.copy(new FileInputStream(f), out);
}
Example 15
Project: hank-master  File: DeflateCompressor.java View source code
@Override
public OutputStream getOutputStream(OutputStream outputStream) {
    Deflater deflater = new Deflater();
    deflater.setLevel(Deflater.BEST_COMPRESSION);
    deflater.setStrategy(Deflater.DEFAULT_STRATEGY);
    return new DeflaterOutputStream(outputStream, deflater);
}
Example 16
Project: android-15-master  File: CarouselViewUtilities.java View source code
/**
     * Debug utility to write the given bitmap to a file.
     *
     * @param context calling context
     * @param bitmap the bitmap to write
     * @param filename the name of the file to write
     * @return
     */
public static boolean writeBitmapToFile(Context context, Bitmap bitmap, String filename) {
    File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    File file = new File(path, filename);
    boolean result = false;
    try {
        path.mkdirs();
        OutputStream os = new FileOutputStream(file);
        MediaScannerConnection.scanFile(context, new String[] { file.toString() }, null, null);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, os);
        result = true;
    } catch (IOException e) {
        Log.w("ExternalStorage", "Error writing " + file, e);
    }
    return result;
}
Example 17
Project: geoserver-enterprise-master  File: DescribeProcessResponse.java View source code
public void write(Object value, OutputStream output, Operation operation) throws IOException {
    TransformerBase tx = (TransformerBase) value;
    try {
        tx.transform(operation.getParameters()[0], output);
    } catch (TransformerException e) {
        throw (IOException) new IOException().initCause(e);
    }
    return;
}
Example 18
Project: vr-toolkit-master  File: DownloadFiles.java View source code
@Override
protected String doInBackground(String... sUrl) {
    try {
        URL url = new URL(sUrl[0]);
        URLConnection connection = url.openConnection();
        connection.connect();
        // this will be useful so that you can show a typical 0-100% progress bar
        int fileLength = connection.getContentLength();
        // download the file
        InputStream input = new BufferedInputStream(url.openStream());
        OutputStream output = new FileOutputStream(mPath);
        byte data[] = new byte[1024];
        long total = 0;
        int count;
        while ((count = input.read(data)) != -1) {
            total += count;
            // publishing the progress....
            publishProgress((int) (total * 100 / fileLength));
            output.write(data, 0, count);
        }
        output.flush();
        output.close();
        input.close();
    } catch (Exception e) {
    }
    return null;
}
Example 19
Project: fastdfs-client-java-master  File: UploadStream.java View source code
/**
	* send file content callback function, be called only once when the file uploaded
	* @param out output stream for writing file content
	* @return 0 success, return none zero(errno) if fail
	*/
public int send(OutputStream out) throws IOException {
    long remainBytes = fileSize;
    byte[] buff = new byte[256 * 1024];
    int bytes;
    while (remainBytes > 0) {
        try {
            if ((bytes = inputStream.read(buff, 0, remainBytes > buff.length ? buff.length : (int) remainBytes)) < 0) {
                return -1;
            }
        } catch (IOException ex) {
            ex.printStackTrace();
            return -1;
        }
        out.write(buff, 0, bytes);
        remainBytes -= bytes;
    }
    return 0;
}
Example 20
Project: richfaces-master  File: MediaBean.java View source code
public void process(OutputStream outStream, Object data) throws Exception {
    colors = ((MediaData) data).getNewColors();
    ExternalContext extContext = FacesContext.getCurrentInstance().getExternalContext();
    BufferedInputStream inStream = new BufferedInputStream(extContext.getResourceAsStream(RICHFACES_MEDIA_OUTPUT_IMAGE_SOURCE), BUFFER_SIZE);
    try {
        // skip 8-bytes of header
        byte[] bs = new byte[8];
        if (inStream.read(bs) < bs.length) {
            throw new IllegalArgumentException();
        }
        outStream.write(bs);
        mr.write(colors, outStream, inStream);
    } finally {
        inStream.close();
        outStream.close();
    }
}
Example 21
Project: property-db-master  File: CarouselViewUtilities.java View source code
/**
     * Debug utility to write the given bitmap to a file.
     *
     * @param context calling context
     * @param bitmap the bitmap to write
     * @param filename the name of the file to write
     * @return
     */
public static boolean writeBitmapToFile(Context context, Bitmap bitmap, String filename) {
    File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
    File file = new File(path, filename);
    boolean result = false;
    try {
        path.mkdirs();
        OutputStream os = new FileOutputStream(file);
        MediaScannerConnection.scanFile(context, new String[] { file.toString() }, null, null);
        bitmap.compress(Bitmap.CompressFormat.PNG, 100, os);
        result = true;
    } catch (IOException e) {
        Log.w("ExternalStorage", "Error writing " + file, e);
    }
    return result;
}
Example 22
Project: extension-aws-master  File: Mp4Generator.java View source code
protected InputStream streamBinary(WebPageRequest inReq, Page inPage, InputStream in, long start, long end, long length, Output inOut) throws IOException {
    if (start == -1) {
        //Only used for flash flv files never used for mp4
        String startbytes = inReq.getRequestParameter("start");
        if (startbytes != null) {
            double timeoffset = Double.parseDouble(startbytes);
            OutputStream stream = inOut.getStream();
            getVideoEditor().split(inPage, timeoffset, stream);
            stream.flush();
            return in;
        }
    }
    return super.streamBinary(inReq, inPage, in, start, end, length, inOut);
}
Example 23
Project: milton2-master  File: MemoryMessageResource.java View source code
public void writeTo(OutputStream out) {
    MimeMessage mm = new MimeMessage((Session) null);
    factory.toMimeMessage(message, mm);
    try {
        mm.writeTo(out);
    } catch (IOException ex) {
        throw new RuntimeException(ex);
    } catch (MessagingException ex) {
        throw new RuntimeException(ex);
    }
}
Example 24
Project: polly-master  File: BandwidthManager.java View source code
public BandwidthOutputStream newManagedOutput(OutputStream out, AllocationStrategy subStrategy) {
    final BandwidthOutputStream r = new BandwidthOutputStream(out, this.outputStrategy);
    this.setSubStrategy(r, subStrategy);
    this.outputEvents.addListener(StrategyChangedListener.class, r);
    return r;
}
Example 25
Project: fdroidclient-master  File: AssetUtils.java View source code
@Nullable
public static File copyAssetToDir(Context context, String assetName, File directory) {
    File tempFile = null;
    InputStream input = null;
    OutputStream output = null;
    try {
        tempFile = File.createTempFile(assetName, ".testasset", directory);
        Log.i(TAG, "Copying asset file " + assetName + " to directory " + directory);
        input = context.getAssets().open(assetName);
        output = new FileOutputStream(tempFile);
        Utils.copy(input, output);
    } catch (IOException e) {
        fail(e.getMessage());
    } finally {
        Utils.closeQuietly(output);
        Utils.closeQuietly(input);
    }
    return tempFile;
}