List of usage examples for java.io BufferedOutputStream BufferedOutputStream
public BufferedOutputStream(OutputStream out)
From source file:backend.translator.GTranslator.java
private File downloadFile(String url) throws IOException { HttpClient client = HttpClientBuilder.create().build(); HttpGet request = new HttpGet(url); request.addHeader("User-Agent", "Mozilla/5.0"); HttpResponse response = client.execute(request); HttpEntity entity = response.getEntity(); BufferedInputStream bis = new BufferedInputStream(entity.getContent()); File f = new File(R.TRANS_RESULT_PATH); BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(f)); int inByte;/*from ww w . java 2s . com*/ while ((inByte = bis.read()) != -1) bos.write(inByte); bis.close(); bos.close(); return f; }
From source file:jp.co.opentone.bsol.linkbinder.util.AttachmentUtil.java
/** * ?????.//from w ww .j a v a 2 s . c om * @param randomId ????????? * @param baseName ?????. ????? * @param in ???? * @throws IOException ?? * @return ???? */ public static String createTempporaryFile(String randomId, String baseName, InputStream in) throws IOException { String result = createFileName(randomId, baseName); InputStream bin = null; BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(result)); try { bin = new BufferedInputStream(in); //CHECKSTYLE:OFF byte[] buf = new byte[1024 * 4]; //CHECKSTYLE:ON int len; while ((len = bin.read(buf, 0, buf.length)) != -1) { out.write(buf, 0, len); } return result; } finally { if (bin != null) { bin.close(); } out.close(); } }
From source file:doclet.RefGuideDoclet.java
public static boolean start(RootDoc root) { File dir = new File(REF_GUIDE_DIR); dir.mkdirs();//from w w w. j av a2 s .co m FileOutputStream fos = null; BufferedOutputStream bos = null; PrintWriter pw = null; List<Heading> toc_list = new ArrayList<Heading>(); Map<String, Heading> toc_map = new HashMap<String, Heading>(); try { fos = new FileOutputStream(REF_GUIDE_DIR + "/index.html"); bos = new BufferedOutputStream(fos); pw = new PrintWriter(bos); writePreamble(pw); List<List<Heading>> headings = getHeadings(USER_GUIDE, 1); System.out.println("Headings:"); Heading user_guide = new Heading("User Guide", "User Guide"); int level = 0; toc_list.add(user_guide); for (List<Heading> list : headings) { for (Heading h : list) { System.out.println("ID: " + h.getId() + " Text: " + h.getText()); user_guide.add(h); } level++; } for (ClassDoc classd : root.classes()) { if (classd.isAbstract()) { continue; } PackageDoc pack = classd.containingPackage(); String pname = pack.name(); String display = packageTOCName.get(pname); if (display != null) { pname = display; } System.out.println("package name:" + pname); Heading classes = toc_map.get(pname); if (classes == null) { classes = new Heading(pname, pname); toc_map.put(pname, classes); toc_list.add(classes); } classes.add(new Heading(classd.name(), classd.name())); } writeTOC(pw, toc_list); String current_package = null; pw.println("<div class=\"span-9 last right\">"); writeStaticFile(pw, USER_GUIDE); for (ClassDoc classd : root.classes()) { if (classd.isAbstract()) { continue; } if (ignoreMethods.size() == 0) { initIgnoreMethods(classd.findClass("Object")); } System.out.println("Class: " + classd.name()); PackageDoc pack = classd.containingPackage(); String pname = pack.name(); copyDocFiles(pname); String display = packageTOCName.get(pname); if (display != null) { pname = display; } if (current_package == null || !current_package.equals(pname)) { if (current_package != null) { pw.println("</div>"); } pw.println("<div class=\"domain-container\" id=\"" + pname + "\">"); pw.println("<div class=\"api-domain-header\">" + pname + "</div>"); pw.println("<div class=\"api-domain-desc\" ></div>"); } current_package = display; pw.println(" <div class=\"domain-endpoint\" id=\"" + classd.name() + "\">"); pw.println("<div class=\"api-endpoint-header\">" + classd.name() + "</div>"); pw.println("<div class=\"api-endpoint-desc\">"); System.out.println("Here"); String upd_comment = updateURL(classd.commentText(), pack.name().replace(".", "/") + "/" + "doc-files"); pw.println(upd_comment); pw.println("</div>"); ConstructorDoc[] constructors = classd.constructors(); System.out.println(classd); System.out.println("Constructors:"); for (ConstructorDoc cd : constructors) { pw.println("<div class=\"api-endpoint-parameters\">"); StringBuilder sb = new StringBuilder(); sb.append(cd.name()); sb.append("("); Parameter[] params = cd.parameters(); for (int i = 0; i < params.length; i++) { Parameter param = params[i]; System.out.println(" Param: " + param.name() + " type: " + param.type()); sb.append(param.name()); if (i != params.length - 1) { sb.append(","); } } sb.append(")\n"); if (cd.commentText() != null) { // TODO: make a different css style? sb.append("<div class=\"api-endpoint-desc\">"); sb.append(cd.commentText()); sb.append("</div>"); } pw.println(sb.toString()); System.out.println("Comment: " + cd.commentText()); System.out.println("Printing method annots"); AnnotationDesc[] annots = cd.annotations(); System.out.println(java.util.Arrays.toString(annots)); ParamTag[] tags = cd.paramTags(); pw.println(" <table class=\"api-endpoint-parameters-table\">"); for (int i = 0; i < params.length; i++) { /* <tr class="api-endpoint-parameters-table-row"> <td class="api-endpoint-parameters-table-name-col">x</td> <td class="api-endpoint-parameters-table-type-col">double</td> <td class="api-endpoint-parameters-table-desc-col"> The center x</td> </tr> */ Parameter param = params[i]; System.out.println(" Param: " + param.name() + " type: " + param.type()); pw.println(" <tr class=\"api-endpoint-parameters-table-row\">"); pw.println(" <td class=\"api-endpoint-parameters-table-name-col\">" + param.typeName() + " " + param.name() + "</td>"); //pw.println(" <td class=\"api-endpoint-parameters-table-type-col\">" + param.typeName() + "</td>"); pw.println(" <td class=\"api-endpoint-parameters-table-desc-col\">"); ParamTag comment = getComment(tags, param.name()); if (comment != null) { pw.println(comment.parameterComment()); } pw.println(" </td>"); pw.println(" </tr>"); } pw.println("</table>"); pw.println("</div>"); } System.out.println("Methods:"); for (MethodDoc method : classd.methods()) { writeMethod(pw, method, classd); } ClassDoc parent = classd.superclass(); while (parent != null) { System.out.println("Parent: " + parent); System.out.println("Parent is: " + parent + " methods: " + parent.methods().length); for (MethodDoc method : parent.methods()) { writeMethod(pw, method, classd); } parent = parent.superclass(); if (parent != null && parent.name().equals("Object")) { break; } } pw.println(" </div>"); // domain endpoint } pw.println("</div>"); writePostamble(pw); } catch (IOException ioe) { ioe.printStackTrace(); } finally { try { if (pw != null) pw.close(); if (bos != null) bos.close(); if (fos != null) fos.close(); } catch (IOException ioe) { ioe.printStackTrace(); } } return true; }
From source file:jetbrains.exodus.util.CompressBackupUtil.java
@NotNull public static File backup(@NotNull final Backupable target, @NotNull final File backupRoot, @Nullable final String backupNamePrefix, final boolean zip) throws Exception { if (!backupRoot.exists() && !backupRoot.mkdirs()) { throw new IOException("Failed to create " + backupRoot.getAbsolutePath()); }/*from ww w. j a va 2 s .c o m*/ final File backupFile; final BackupStrategy strategy = target.getBackupStrategy(); strategy.beforeBackup(); try { final ArchiveOutputStream archive; if (zip) { final String fileName = getTimeStampedZipFileName(); backupFile = new File(backupRoot, backupNamePrefix == null ? fileName : backupNamePrefix + fileName); final ZipArchiveOutputStream zipArchive = new ZipArchiveOutputStream( new BufferedOutputStream(new FileOutputStream(backupFile))); zipArchive.setLevel(Deflater.BEST_COMPRESSION); archive = zipArchive; } else { final String fileName = getTimeStampedTarGzFileName(); backupFile = new File(backupRoot, backupNamePrefix == null ? fileName : backupNamePrefix + fileName); archive = new TarArchiveOutputStream( new GZIPOutputStream(new BufferedOutputStream(new FileOutputStream(backupFile)))); } try (ArchiveOutputStream aos = archive) { for (final BackupStrategy.FileDescriptor fd : strategy.listFiles()) { if (strategy.isInterrupted()) { break; } final File file = fd.getFile(); if (file.isFile()) { final long fileSize = Math.min(fd.getFileSize(), strategy.acceptFile(file)); if (fileSize > 0L) { archiveFile(aos, fd.getPath(), file, fileSize); } } } } if (strategy.isInterrupted()) { logger.info("Backup interrupted, deleting \"" + backupFile.getName() + "\"..."); IOUtil.deleteFile(backupFile); } else { logger.info("Backup file \"" + backupFile.getName() + "\" created."); } } catch (Throwable t) { strategy.onError(t); throw ExodusException.toExodusException(t, "Backup failed"); } finally { strategy.afterBackup(); } return backupFile; }
From source file:FileCopyUtils.java
/** * Copy the contents of the given byte array to the given output File. * @param in the byte array to copy from * @param out the file to copy to/* ww w . j a va 2s . c om*/ * @throws IOException in case of I/O errors */ public static void copy(byte[] in, File out) throws IOException { ByteArrayInputStream inStream = new ByteArrayInputStream(in); OutputStream outStream = new BufferedOutputStream(new FileOutputStream(out)); copy(inStream, outStream); }
From source file:com.t3.net.LocalLocation.java
@Override public void putContent(ImageWriter writer, BufferedImage image) { try (BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(getFile()))) { writer.setOutput(out);// w ww . ja v a2s . co m writer.write(image); } catch (IOException e) { e.printStackTrace(); } }
From source file:ca.simplegames.micro.utils.IO.java
/** * Copy the contents of the given byte array to the given output File. * * @param in the byte array to copy from * @param out the file to copy to//from w w w . j av a 2s.c om * @throws IOException in case of I/O errors */ public static void copy(byte[] in, File out) throws IOException { ByteArrayInputStream inStream = new ByteArrayInputStream(in); OutputStream outStream = new BufferedOutputStream(new FileOutputStream(out)); copy(inStream, outStream); }
From source file:gaffer.accumulo.utils.IngestUtils.java
/** * Get the existing splits from a table in Accumulo and write a splits file. * The number of splits is returned./* www . j a v a 2 s . c o m*/ * * @param conn An existing connection to an Accumulo instance * @param table The table name * @param fs The FileSystem in which to create the splits file * @param splitsFile A path for the splits file * @return The number of splits in the table * @throws TableNotFoundException * @throws IOException */ public static int createSplitsFile(Connector conn, String table, FileSystem fs, Path splitsFile) throws TableNotFoundException, IOException { // Get the splits from the table Collection<Text> splits = conn.tableOperations().getSplits(table); // Write the splits to file if (splits.isEmpty()) { return 0; } PrintStream out = new PrintStream(new BufferedOutputStream(fs.create(splitsFile, true))); for (Text split : splits) { out.println(new String(Base64.encodeBase64(split.getBytes()))); } out.close(); return splits.size(); }
From source file:com.adaptris.util.stream.StreamUtil.java
/** * Read from the inputstream associated with the socket and write the data * straight out to a unique file in the specified directory * * @param input The inputstream to read from * @param expected the expected number of bytes * @param dir The directory in which to create the file * @return a File object corresponding to the temporary file that was created * @throws IOException if there was an creating the file */// w w w . j a v a2 s.c om public static File createFile(InputStream input, int expected, String dir) throws IOException { File tempFile = null; if (isEmpty(dir)) { tempFile = File.createTempFile("tmp", ""); } else { tempFile = File.createTempFile("tmp", "", new File(dir)); } try (OutputStream out = new BufferedOutputStream(new FileOutputStream(tempFile))) { copyStream(input, out, expected); } return tempFile; }
From source file:eu.itesla_project.iidm.datasource.Bzip2FileDataSource.java
@Override public OutputStream newOutputStream(String suffix, String ext, boolean append) throws IOException { Path path = getPath(suffix, ext); OutputStream os = new BZip2CompressorOutputStream(new BufferedOutputStream( Files.newOutputStream(path, append ? StandardOpenOption.APPEND : StandardOpenOption.CREATE))); return observer != null ? new ObservableOutputStream(os, path.toString(), observer) : os; }