List of usage examples for java.io PrintStream print
public void print(Object obj)
From source file:com.taobao.android.builder.tools.sign.LocalSignedJarBuilder.java
/** * Writes a .SF file with a digest to the manifest. *//*from w ww . j av a 2s. c o m*/ private void writeSignatureFile(OutputStream out) throws IOException, GeneralSecurityException { Manifest sf = new Manifest(); Attributes main = sf.getMainAttributes(); main.putValue("Signature-Version", "1.0"); main.putValue("Created-By", "1.0 (Android)"); MessageDigest md = MessageDigest.getInstance(DIGEST_ALGORITHM); PrintStream print = new PrintStream(new DigestOutputStream(new ByteArrayOutputStream(), md), true, SdkConstants.UTF_8); // Digest of the entire manifest mManifest.write(print); print.flush(); main.putValue(DIGEST_MANIFEST_ATTR, new String(Base64.encode(md.digest()), "ASCII")); Map<String, Attributes> entries = mManifest.getEntries(); for (Map.Entry<String, Attributes> entry : entries.entrySet()) { // Digest of the manifest stanza for this entry. print.print("Name: " + entry.getKey() + "\r\n"); for (Map.Entry<Object, Object> att : entry.getValue().entrySet()) { print.print(att.getKey() + ": " + att.getValue() + "\r\n"); } print.print("\r\n"); print.flush(); Attributes sfAttr = new Attributes(); sfAttr.putValue(DIGEST_ATTR, new String(Base64.encode(md.digest()), "ASCII")); sf.getEntries().put(entry.getKey(), sfAttr); } CountOutputStream cout = new CountOutputStream(out); sf.write(cout); // A bug in the java.util.jar implementation of Android platforms // up to version 1.6 will cause a spurious IOException to be thrown // if the length of the signature file is a multiple of 1024 bytes. // As a workaround, add an extra CRLF in this case. if ((cout.size() % 1024) == 0) { cout.write('\r'); cout.write('\n'); } }
From source file:eu.europa.ec.fisheries.uvms.plugins.inmarsat.twostage.Connect.java
private String issueCommand(PollType poll, PrintStream out, InputStream in, String dnid, String path, String url, String port) throws TelnetException, IOException { String filename = getFileName(path); FileOutputStream stream = null; try {/* www . j av a2 s. com*/ stream = new FileOutputStream(filename); } catch (FileNotFoundException e) { LOG.warn("Could not read/create file for TwoStage Command: {}", filename); } String result; if (poll != null) { result = sendPollCommand(poll, out, in, stream, url, port); } else { result = sendDownloadCommand(out, in, stream, dnid, url, port); } if (stream != null) { stream.flush(); stream.close(); //Delete file for polls, these are persisted elsewhere if (poll != null) { File f = new File(filename); if (f.exists() && f.isFile()) { f.delete(); } } } out.print("QUIT \r\n"); out.flush(); return result; }
From source file:org.dspace.identifier.doi.DOIOrganiser.java
public void list(String processName, PrintStream out, PrintStream err, Integer... status) { String indent = " "; if (null == out) { out = System.out;//from w w w . j a v a2 s . c o m } if (null == err) { err = System.err; } try { List<DOI> doiList = doiService.getDOIsByStatus(context, Arrays.asList(status)); if (0 < doiList.size()) { out.println("DOIs queued for " + processName + ": "); } else { out.println("There are no DOIs queued for " + processName + "."); } for (DOI doiRow : doiList) { out.print(indent + DOI.SCHEME + doiRow.getDoi()); DSpaceObject dso = doiRow.getDSpaceObject(); if (null != dso) { out.println(" (belongs to item with handle " + dso.getHandle() + ")"); } else { out.println(" (cannot determine handle of assigned object)"); } } out.println(""); } catch (SQLException ex) { err.println("Error in database Connection: " + ex.getMessage()); ex.printStackTrace(err); } }
From source file:ca.nines.ise.cmd.Annotations.java
/** * {@inheritDoc}//from w ww . java 2 s .c o m */ @ErrorCode(code = { "dom.errors" }) @Override public void execute(CommandLine cmd) throws Exception { Log log = Log.getInstance(); Locale.setDefault(Locale.ENGLISH); PrintStream logOut = new PrintStream(System.out, true, "UTF-8"); if (cmd.hasOption("l")) { logOut = new PrintStream(new FileOutputStream(cmd.getOptionValue("l")), true, "UTF-8"); } String args[] = getArgList(cmd); File docFile = new File(args[0]); if (!docFile.exists()) { System.err.println("Cannot read document " + docFile.getCanonicalPath()); System.exit(1); } File annFile = new File(args[1]); if (!annFile.exists()) { System.err.println("Cannot read annotations " + annFile.getCanonicalPath()); System.exit(1); } DOM dom = new DOMBuilder(docFile).build(); if (dom.getStatus() != DOM.DOMStatus.ERROR) { Annotation annotation = Annotation.builder().from(annFile).build(); AnnotationValidator av = new AnnotationValidator(); av.validate(dom, annotation); } else { Message m = Message.builder("dom.errors").setSource(dom.getSource()).build(); log.add(m); } if (log.count() > 0) { logOut.print(log); } }
From source file:com.netscape.cms.publish.publishers.FileBasedPublisher.java
/** * Publishes a object to the ldap directory. * * @param conn a Ldap connection//from w w w . ja v a 2 s . co m * (null if LDAP publishing is not enabled) * @param dn dn of the ldap entry to publish cert * (null if LDAP publishing is not enabled) * @param object object to publish * (java.security.cert.X509Certificate or, * java.security.cert.X509CRL) */ public void publish(LDAPConnection conn, String dn, Object object) throws ELdapException { CMS.debug("FileBasedPublisher: publish"); try { if (object instanceof X509Certificate) { X509Certificate cert = (X509Certificate) object; BigInteger sno = cert.getSerialNumber(); String name = mDir + File.separator + "cert-" + sno.toString(); if (mDerAttr) { FileOutputStream fos = null; try { String fileName = name + ".der"; fos = new FileOutputStream(fileName); fos.write(cert.getEncoded()); } finally { if (fos != null) fos.close(); } } if (mB64Attr) { String fileName = name + ".b64"; PrintStream ps = null; Base64OutputStream b64 = null; FileOutputStream fos = null; try { fos = new FileOutputStream(fileName); ByteArrayOutputStream output = new ByteArrayOutputStream(); b64 = new Base64OutputStream(new PrintStream(new FilterOutputStream(output))); b64.write(cert.getEncoded()); b64.flush(); ps = new PrintStream(fos); ps.print(output.toString("8859_1")); } finally { if (ps != null) { ps.close(); } if (b64 != null) { b64.close(); } if (fos != null) fos.close(); } } } else if (object instanceof X509CRL) { X509CRL crl = (X509CRL) object; String[] namePrefix = getCrlNamePrefix(crl, mTimeStamp.equals("GMT")); String baseName = mDir + File.separator + namePrefix[0]; String tempFile = baseName + ".temp"; ZipOutputStream zos = null; byte[] encodedArray = null; File destFile = null; String destName = null; File renameFile = null; if (mDerAttr) { FileOutputStream fos = null; try { fos = new FileOutputStream(tempFile); encodedArray = crl.getEncoded(); fos.write(encodedArray); } finally { if (fos != null) fos.close(); } if (mZipCRL) { try { zos = new ZipOutputStream(new FileOutputStream(baseName + ".zip")); zos.setLevel(mZipLevel); zos.putNextEntry(new ZipEntry(baseName + ".der")); zos.write(encodedArray, 0, encodedArray.length); zos.closeEntry(); } finally { if (zos != null) zos.close(); } } destName = baseName + ".der"; destFile = new File(destName); if (destFile.exists()) { destFile.delete(); } renameFile = new File(tempFile); renameFile.renameTo(destFile); if (mLatestCRL) { String linkExt = "."; if (mLinkExt != null && mLinkExt.length() > 0) { linkExt += mLinkExt; } else { linkExt += "der"; } String linkName = mDir + File.separator + namePrefix[1] + linkExt; createLink(linkName, destName); if (mZipCRL) { linkName = mDir + File.separator + namePrefix[1] + ".zip"; createLink(linkName, baseName + ".zip"); } } } // output base64 file if (mB64Attr == true) { if (encodedArray == null) encodedArray = crl.getEncoded(); FileOutputStream fos = null; try { fos = new FileOutputStream(tempFile); fos.write(Utils.base64encode(encodedArray, true).getBytes()); } finally { if (fos != null) fos.close(); } destName = baseName + ".b64"; destFile = new File(destName); if (destFile.exists()) { destFile.delete(); } renameFile = new File(tempFile); renameFile.renameTo(destFile); } purgeExpiredFiles(); purgeExcessFiles(); } } catch (IOException e) { mLogger.log(ILogger.EV_SYSTEM, ILogger.S_OTHER, ILogger.LL_FAILURE, CMS.getLogMessage("PUBLISH_FILE_PUBLISHER_ERROR", e.toString())); } catch (CertificateEncodingException e) { mLogger.log(ILogger.EV_SYSTEM, ILogger.S_OTHER, ILogger.LL_FAILURE, CMS.getLogMessage("PUBLISH_FILE_PUBLISHER_ERROR", e.toString())); } catch (CRLException e) { mLogger.log(ILogger.EV_SYSTEM, ILogger.S_OTHER, ILogger.LL_FAILURE, CMS.getLogMessage("PUBLISH_FILE_PUBLISHER_ERROR", e.toString())); } }
From source file:es.cnio.bioinfo.bicycle.gatk.MethylationFilePair.java
private void flushCrick() { PrintStream stream; try {/*from w w w . ja va2 s .co m*/ stream = new PrintStream(new BufferedOutputStream(new FileOutputStream(crickFile, true))); stream.print(crickBuffer.toString()); crickBuffer.setLength(0); stream.flush(); stream.close(); printCrickCount = 0; } catch (FileNotFoundException e) { throw new RuntimeException(e); } }
From source file:com.bigdata.dastor.tools.DastorAdminCli.java
/** * Write a textual representation of the Dastor ring. * /*from w w w.jav a 2 s.c om*/ * @param outs the stream to write to */ public void printRing(PrintStream outs) { Map<Range, List<String>> rangeMap = probe.getRangeToEndPointMap(null); List<Range> ranges = new ArrayList<Range>(rangeMap.keySet()); Collections.sort(ranges); Set<String> liveNodes = probe.getLiveNodes(); Set<String> deadNodes = probe.getUnreachableNodes(); Map<String, String> loadMap = probe.getLoadMap(); // Print range-to-endpoint mapping int counter = 0; outs.print(String.format("%-14s", "PrimaryNode")); outs.print(String.format("%-11s", "Status")); outs.print(String.format("%-14s", "Load")); outs.print(String.format("%-43s", "PositionCode")); outs.println(" Replicas"); // emphasize that we're showing the right part of each range if (ranges.size() > 1) { outs.println(String.format("%-14s%-11s%-14s%-43s", "", "", "", ranges.get(0).left)); } // normal range & node info for (Range range : ranges) { List<String> endpoints = rangeMap.get(range); String primaryEndpoint = endpoints.get(0); outs.print(String.format("%-14s", primaryEndpoint)); String status = liveNodes.contains(primaryEndpoint) ? "Up" : deadNodes.contains(primaryEndpoint) ? "Down" : "?"; outs.print(String.format("%-11s", status)); String load = loadMap.containsKey(primaryEndpoint) ? loadMap.get(primaryEndpoint) : "?"; outs.print(String.format("%-14s", load)); outs.print(String.format("%-43s", range.right)); for (int i = 1; i < endpoints.size(); i++) { String ep = endpoints.get(i); String epsta = liveNodes.contains(ep) ? "u" : deadNodes.contains(primaryEndpoint) ? "d" : "?"; outs.print(" " + ep + "[" + epsta + "]"); } outs.println(""); /* String asciiRingArt; if (counter == 0) { asciiRingArt = "|<--|"; } else if (counter == (rangeMap.size() - 1)) { asciiRingArt = "|-->|"; } else { if ((rangeMap.size() > 4) && ((counter % 2) == 0)) asciiRingArt = "v |"; else if ((rangeMap.size() > 4) && ((counter % 2) != 0)) asciiRingArt = "| ^"; else asciiRingArt = "| |"; } outs.println(asciiRingArt); counter++; */ } }
From source file:es.cnio.bioinfo.bicycle.gatk.MethylationFilePair.java
private void flushWatson() { PrintStream stream; try {/*ww w . j a va 2 s . com*/ stream = new PrintStream(new BufferedOutputStream(new FileOutputStream(watsonFile, true))); stream.print(watsonBuffer.toString()); watsonBuffer.setLength(0); stream.flush(); stream.close(); printWatsonCount = 0; } catch (FileNotFoundException e) { throw new RuntimeException(e); } }
From source file:org.eclipse.orion.server.git.jobs.CloneJob.java
private IStatus doClone() { try {// w ww . ja va 2 s . c o m File cloneFolder = new File(clone.getContentLocation().getPath()); if (!cloneFolder.exists()) { cloneFolder.mkdir(); } CloneCommand cc = Git.cloneRepository(); cc.setBare(false); cc.setCredentialsProvider(credentials); cc.setDirectory(cloneFolder); cc.setRemote(Constants.DEFAULT_REMOTE_NAME); cc.setURI(clone.getUrl()); Git git = cc.call(); // Configure the clone, see Bug 337820 GitCloneHandlerV1.doConfigureClone(git, user, gitUserName, gitUserMail); git.getRepository().close(); if (initProject) { File projectJsonFile = new File(cloneFolder.getPath() + File.separator + "project.json"); if (!projectJsonFile.exists()) { PrintStream out = null; try { out = new PrintStream(new FileOutputStream(projectJsonFile)); JSONObject projectjson = new JSONObject(); String gitPath = clone.getUrl(); if (gitPath.indexOf("://") > 0) { gitPath = gitPath.substring(gitPath.indexOf("://") + 3); } String[] segments = gitPath.split("/"); String serverName = segments[0]; if (serverName.indexOf("@") > 0) { serverName = serverName.substring(serverName.indexOf("@") + 1); } String repoName = segments[segments.length - 1]; if (repoName.indexOf(".git") > 0) { repoName = repoName.substring(0, repoName.lastIndexOf(".git")); } projectjson.put("Name", repoName + " at " + serverName); out.print(projectjson.toString()); } finally { if (out != null) out.close(); } } } } catch (IOException e) { return new Status(IStatus.ERROR, GitActivator.PI_GIT, "Error cloning git repository", e); } catch (CoreException e) { return e.getStatus(); } catch (GitAPIException e) { return getGitAPIExceptionStatus(e, "Error cloning git repository"); } catch (JGitInternalException e) { return getJGitInternalExceptionStatus(e, "Error cloning git repository"); } catch (Exception e) { return new Status(IStatus.ERROR, GitActivator.PI_GIT, "Error cloning git repository", e); } JSONObject jsonData = new JSONObject(); try { jsonData.put(ProtocolConstants.KEY_LOCATION, URI.create(this.cloneLocation)); } catch (JSONException e) { // Should not happen } return new ServerStatus(Status.OK_STATUS, HttpServletResponse.SC_OK, jsonData); }
From source file:es.cnio.bioinfo.bicycle.gatk.MethylationFilePair.java
private void writeVCFRecord(PrintStream out, MethylationCall call) { double cutOff = this.cutOffs.get(call.getStrand()).get(call.getContext()); out.print(call.getContig() + "\t"); out.print(call.getPosition() + "\t"); out.print(call.getContext() + "\t"); out.print("C\t"); if (call.getPval() < cutOff) { out.print("C\t"); } else {/*www.j av a 2s. com*/ out.print(".\t"); } out.print(".\t.\t"); //info out.print("NS=1;"); out.print("DP=" + call.getDepth() + ";"); out.print("CTDP=" + call.getCTdepth() + ";"); out.print("CD=" + call.getCytosines() + ";"); //modified (osvaldo, 3jan2016) //out.print("PER="+new DecimalFormat("###.##").format(100*(double)call.getCytosines()/(double)call.getDepth()) // +";"); out.print("BS=" + new DecimalFormat("#.#######").format(call.getBetaScore()) + ";"); out.print("PU=" + call.getPileup() + ";"); if (call.isCorrectedFromNonCG()) { out.print("CO;"); } if (call.isAddedByCorrection()) { out.print("AC;"); } out.print("STR=" + (call.getStrand() == Strand.WATSON ? "+" : "-") + ";"); for (int i = 0; i < this.beds.size(); i++) { out.print(this.beds.get(i).getName() + "=" + call.getAnnotations().get(i) + ";"); } out.println(); }