private static boolean checkSHA256(File provingKey, Component parent) throws IOException { MessageDigest sha256; try { sha256 = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException impossible) { throw new IOException(impossible); } try (InputStream is = new BufferedInputStream(new FileInputStream(provingKey))) { ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(parent,"Verifying proving key",is); pmis.getProgressMonitor().setMaximum(PROVING_KEY_SIZE); pmis.getProgressMonitor().setMillisToPopup(10); DigestInputStream dis = new DigestInputStream(pmis, sha256); byte [] temp = new byte[0x1 << 13]; while(dis.read(temp) >= 0); byte [] digest = sha256.digest(); return SHA256.equalsIgnoreCase(DatatypeConverter.printHexBinary(digest)); } }
private static boolean checkSHA256(File provingKey, Component parent) throws IOException { MessageDigest sha256; try { sha256 = MessageDigest.getInstance("SHA-256"); } catch (NoSuchAlgorithmException impossible) { throw new RuntimeException(impossible); } try (InputStream is = new BufferedInputStream(new FileInputStream(provingKey))) { ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(parent,"Verifying proving key",is); pmis.getProgressMonitor().setMaximum(PROVING_KEY_SIZE); pmis.getProgressMonitor().setMillisToPopup(10); DigestInputStream dis = new DigestInputStream(pmis, sha256); byte [] temp = new byte[0x1 << 13]; while(dis.read(temp) >= 0); byte [] digest = sha256.digest(); return SHA256.equalsIgnoreCase(DatatypeConverter.printHexBinary(digest)); } }
public void download() throws Exception { if (!downloadNeeded) { return; } logger.info("Downloading: "+this.downloadUrl); if (!DEBUG) { this.mkdir(); URL url = new URL(this.downloadUrl); URLConnection urlConn = url.openConnection(); urlConn.setConnectTimeout(10000); urlConn.setReadTimeout(10000); InputStream is = urlConn.getInputStream(); ProgressMonitorInputStream pim = new ProgressMonitorInputStream(null, "Downloading "+ downloadUrl,is); logger.info("File Size: "+this.remoteFileSize); pim.getProgressMonitor().setMaximum((int) this.remoteFileSize); pim.getProgressMonitor().setMillisToDecideToPopup(500); logger.info("Starting Download..."); Files.copy(pim, localFile.toPath(),StandardCopyOption.REPLACE_EXISTING); } }
@Override public Void doInBackground() { String rawString = configManager.getRawString(); try { stream = new ProgressMonitorInputStream(null, (Object) "Flashing", new ByteArrayInputStream(rawString .getBytes(HacklaceConfigManager.HACKLACE_CHARSET))); ProgressMonitor progressMonitor = stream.getProgressMonitor(); progressMonitor.setMaximum(rawString.length()); progressMonitor.setProgress(0); progressMonitor.setMillisToPopup(0); animatorGui.setCursor(Cursor .getPredefinedCursor(Cursor.WAIT_CURSOR)); flashExporter.write(stream); } catch (Exception ex) { JOptionPane.showMessageDialog(null, "Error flashing hacklace: " + ex, "Error", JOptionPane.ERROR_MESSAGE); } return null; }
/** Performs loading a serialized java object by poping a progress monitor.*/ @SuppressWarnings("unchecked") public static <O> O load(String filename, Component parentComponent, String message) throws IOException, ClassNotFoundException { final FileInputStream fis = new FileInputStream(filename); final ObjectInputStream in; if(parentComponent!=null){ final ProgressMonitorInputStream pm = new ProgressMonitorInputStream(parentComponent, message, fis); in = new ObjectInputStream(pm); } else{ in = new ObjectInputStream(fis); } O r = (O) in.readObject(); in.close(); fis.close(); return r; }
private void addDumpStream(InputStream inputStream, String file, boolean withLogfile) { final InputStream parseFileStream = new ProgressMonitorInputStream(this, "Parsing " + file, inputStream); //Create the nodes. if(!runningAsJConsolePlugin || topNodes.size() == 0) { topNodes.add(new DefaultMutableTreeNode(new Logfile(file))); } final DefaultMutableTreeNode top = (DefaultMutableTreeNode) topNodes.get(topNodes.size()-1); if ((!withLogfile && logFile == null) || isLogfileSizeOk(file)) { logFile = new DefaultMutableTreeNode(new LogFileContent(file)); if(!runningAsVisualVMPlugin) { top.add(logFile); } } setFileOpen(true); final SwingWorker worker = new SwingWorker() { public Object construct() { synchronized (syncObject) { int divider = topSplitPane.getDividerLocation(); addThreadDumps(top, parseFileStream); createTree(); tree.expandRow(1); topSplitPane.setDividerLocation(divider); } return null; } }; worker.start(); }
/** Creates a new instance of LRGBReader */ public RGBReader(InputStream in) { __in = new ProgressMonitorInputStream(null, "Reading...", in); __in.getProgressMonitor().setMillisToDecideToPopup(0); __in.getProgressMonitor().setMillisToPopup(0); }
/** * Decodes a File into a Vector of LoggingEvents. * * @param url the url of a file containing events to decode * @return Vector of LoggingEvents * @throws IOException if IO error during processing. */ public Vector decode(final URL url) throws IOException { LineNumberReader reader; if (owner != null) { reader = new LineNumberReader(new InputStreamReader(new ProgressMonitorInputStream(owner, "Loading " + url, url.openStream()))); } else { reader = new LineNumberReader(new InputStreamReader(url.openStream())); } Vector v = new Vector(); String line; Vector events; try { while ((line = reader.readLine()) != null) { StringBuilder buffer = new StringBuilder(line); for (int i = 0; i < 1000; i++) { buffer.append(reader.readLine()).append("\n"); } events = decodeEvents(buffer.toString()); if (events != null) { v.addAll(events); } } } finally { partialEvent = null; try { if (reader != null) { reader.close(); } } catch (Exception e) { e.printStackTrace(); } } return v; }
public static InputStream getInputStreamWithProgressMonitor(InputStream input, Component parentComponent, String message) { if (input == null) return null ; Frame owner = null; if (parentComponent == null) owner = SwingUtils.tryFindSuitableFrameOwner () ; InputStream in = new BufferedInputStream( new ProgressMonitorInputStream( (parentComponent == null) ? (owner) : (parentComponent), message, input)); return in; }
/** * Reads xmppdump formatted data from the given file, and loads it into the * embedded database. Does not clear any pre-existing contents. * @param f File to be loaded. */ public void loadFromFile(final File f) { try { // funnel file reads through a progress monitor final ProgressMonitorInputStream pmis = new ProgressMonitorInputStream( xmpptrace.view.XmppTraceFrame.getInstance(), "Reading " + f.getName() + "...", new FileInputStream(f)); pmis.getProgressMonitor().setMillisToPopup(0); // do the file loading on background thread so progmon will show new Thread() { public void run() { // create a parser on an input stream from the file if (f.getName().endsWith(".pcap")) { Database.this.readPacketsFromStream( new TcpDumpStreamParser(pmis)); } else { Database.this.readPacketsFromStream( new XmppDumpStreamParser(pmis)); } } }.start(); } catch (IOException e) { e.printStackTrace(); } }
public InputStream getProgressMonitorInputStream(InputStream in, int length, String msg) { ProgressMonitorInputStream pmin = new ProgressMonitorInputStream(parent, msg, in); ProgressMonitor pm = pmin.getProgressMonitor(); if (length > 0) pm.setMaximum(length); return pmin; }
public void loadExcelFile(File f){ try { int length = (int)f.length(); JDialog d = new JDialog((Frame)null, "Loading File"); JPanel p = new JPanel(new BorderLayout()); p.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); d.setLocationRelativeTo(null); JProgressBar pb = new JProgressBar(0,length); p.add(new JLabel("Loading " + (length / 1000) + " kb file"), BorderLayout.NORTH); p.add(pb); d.getContentPane().add(p); d.pack(); d.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); d.setVisible(true); d.setAlwaysOnTop(true); Workbook wb = Workbook.getWorkbook(new ProgressMonitorInputStream(this,"Loading",new FileInputStream(f))); if (wb.getNumberOfSheets()==0)return; Sheet s = wb.getSheet(0); StringBuffer sb = new StringBuffer(); for (int i = 0; i < s.getRows(); i++) { for (int j = 0; j < s.getColumns(); j++) { if (s.getCell(j, i).getType() == CellType.NUMBER && !s.getCell(j, i).getContents().matches("\\d*")) { pb.setValue(pb.getValue()+ 16); pb.repaint(); sb.append(((NumberCell)s.getCell(j, i)).getValue()+"\t"); } else { pb.setValue(pb.getValue() + 2*s.getCell(j, i).getContents().length() + 36); pb.repaint(); sb.append(s.getCell(j, i).getContents()+"\t"); } } sb.append("\n"); } name.setText(f.getName().substring(0, f.getName().lastIndexOf('.'))); input.setText(sb.toString()); wb.close(); d.dispose(); } catch (Exception e) { JOptionPane.showMessageDialog(null, "Error loading file:\n"+e.getMessage(), "Error", JOptionPane.ERROR_MESSAGE); return; } }
public Vector loadVenueData(Component parent) throws Exception { headers = null; Socket s = null; ProgressMonitor progress = null; Vector venues = null; try { StallInputStream stallInput = new StallInputStream(); ProgressMonitorInputStream pmis = new ProgressMonitorInputStream( parent, "Loading filter data from pente.org", stallInput); progress = pmis.getProgressMonitor(); progress.setNote("Connecting to pente.org..."); progress.setMillisToDecideToPopup(1); progress.setMillisToPopup(1); progress.setMaximum(15000); StringBuffer paramsBuffer = new StringBuffer(); StringBuffer requestBuffer = createHttpRequest(paramsBuffer, "/venues"); int len = 0; s = getHttpResponseSocket(requestBuffer); progress.setProgress(2000); progress.setNote("Downloading from pente.org..."); // read past the http headers to the data InputStream in = s.getInputStream(); String contentLength = getHeader("content-length:", in); if (contentLength != null) { len = Integer.parseInt(contentLength); } // for (int i = 0; i < len; i++) { // int b = in.read(); // if (b == -1) { // System.out.println("error"); // } // } progress.setMaximum(len); stallInput.setInputStream(in); ObjectInputStream objectIn = new ObjectInputStream(pmis); venues = (Vector) objectIn.readObject(); } catch (Exception e) { if (s != null) { s.close(); s = null; } if (!(e instanceof InterruptedException) && !(progress == null || !progress.isCanceled())) { throw e; } } return venues; }