public void run() { String[] sData; while (oConn.isConnected()) { sData = oConn.getData(); System.out.println("Received \"" + sData[0] + "\" command."); if (sData[0].equals("chat")) panChat.addChat(sData[1]); else if (sData[0].equals("loadmap")) { try { oMap.loadMap(new File(DEFAULT_MAP_DIRECTORY + sData[1])); int nRand = (int) Math.floor((Math.random() + 1) + 0.5); stateDeploy(nRand); if (nRand == 1) nRand = 2; else nRand = 1; oConn.send("deploy", "" + nRand); } catch (FileNotFoundException e) { oConn.send("error", "Opponent does not have map."); actionDisconnect(); } } else if (sData[0].equals("deploy")) { stateDeploy(Integer.parseInt(sData[1])); } else if (sData[0].equals("error")) { JOptionPane.showMessageDialog(frame, sData[1]); actionDisconnect(); } else if (sData[0].equals("deployed")) { bOpponentDeployed = true; if (bDeployed) { oConn.send("trade parties", ""); tradeParties(); makeAvatarOrder(); long nRandSeed = Math.round((Math.random() * Long.MAX_VALUE)); oRandom = new Random(nRandSeed); oConn.send("random seed", "" + nRandSeed); oConn.send("phase", "1"); phase1(); } } else if (sData[0].equals("trade parties")) { tradeParties(); } else if (sData[0].equals("avatar order")) { makeAvatarOrder(sData[1]); } else if (sData[0].equals("random seed")) { oRandom = new Random(Long.parseLong(sData[1])); } else if (sData[0].equals("phase")) { switch (Integer.parseInt(sData[1])) { case 1: phase1(); break; case 2: phase2(); break; case 3: phase3(); break; case 4: iChar = 0; bMyAT = false; phase4(); break; } } else if (sData[0].equals("move")) { oMap.moveATAvatar(Integer.parseInt(sData[1]), Integer.parseInt(sData[2])); // TEMP stateEndTurn(); } } }
/** * Returns the editted value. * * @return the editted value. * @throws TagFormatException if the tag value cannot be retrieved with the expected type. */ public TagValue getTagValue() throws TagFormatException { try { long numer = Long.parseLong(m_numer.getText()); long denom = Long.parseLong(m_denom.getText()); Rational rational = new Rational(numer, denom); return new TagValue(m_value.getTag(), rational); } catch (NumberFormatException e) { e.printStackTrace(); throw new TagFormatException( m_numer.getText() + "/" + m_denom.getText() + " is not a valid rational"); } }
@Override public Object stringToValue(String text) throws ParseException { if (text != null) text = text.trim(); if ((text == null) || text.isEmpty()) { if (nullable) { return null; } else { throw new ParseException("Empty/null value is not allowed.", 0); } } long value; try { value = Long.parseLong(text); } catch (Exception e) { throw new ParseException("Parsing \"" + text + "\" to an integer value failed.", 0); } if ((value < minValue) || (value > maxValue)) { throw new ParseException( "Parsing \"" + text + "\" to an integer value in the range [" + minValue + ", " + maxValue + "] failed.", 0); } return value; }
public void actionPerformed(ActionEvent e) { try { TransferProveedor Proveedor = new TransferProveedor(); Proveedor.setId(Integer.parseInt(labelId.getText())); cajaNIF.setBackground(Color.red); Proveedor.setNif(Integer.parseInt(cajaNIF.getText())); if (Proveedor.getNif() < 0) throw new NumberFormatException(); cajaNIF.setBackground(Color.green); cajaNombre.setBackground(Color.red); if (cajaNombre.getText().equals("")) throw new InputMismatchException(); Proveedor.setName(cajaNombre.getText()); cajaNombre.setBackground(Color.green); cajaTelefono.setBackground(Color.red); Proveedor.setTelephoneNumber(Long.parseLong(cajaTelefono.getText())); if (Proveedor.getTelephoneNumber() < 0) throw new NumberFormatException(); cajaTelefono.setBackground(Color.green); cajaEmail.setBackground(Color.red); if (cajaEmail.getText().equals("")) throw new InputMismatchException(); Proveedor.setEmail(cajaEmail.getText()); cajaEmail.setBackground(Color.green); ControladorAplicacion.getInstancia().accion(Acciones.proveedoresEditar, Proveedor); } catch (NumberFormatException ex) { JOptionPane.showMessageDialog(EditarProveedorGUI.this, "Introduce números"); } catch (InputMismatchException ex) { JOptionPane.showMessageDialog(EditarProveedorGUI.this, "No se permiten campos vacios"); } }
public Chart(String filename) { try { // Get Stock Symbol this.stockSymbol = filename.substring(0, filename.indexOf('.')); // Create time series TimeSeries open = new TimeSeries("Open Price", Day.class); TimeSeries close = new TimeSeries("Close Price", Day.class); TimeSeries high = new TimeSeries("High", Day.class); TimeSeries low = new TimeSeries("Low", Day.class); TimeSeries volume = new TimeSeries("Volume", Day.class); BufferedReader br = new BufferedReader(new FileReader(filename)); String key = br.readLine(); String line = br.readLine(); while (line != null && !line.startsWith("<!--")) { StringTokenizer st = new StringTokenizer(line, ",", false); Day day = getDay(st.nextToken()); double openValue = Double.parseDouble(st.nextToken()); double highValue = Double.parseDouble(st.nextToken()); double lowValue = Double.parseDouble(st.nextToken()); double closeValue = Double.parseDouble(st.nextToken()); long volumeValue = Long.parseLong(st.nextToken()); // Add this value to our series' open.add(day, openValue); close.add(day, closeValue); high.add(day, highValue); low.add(day, lowValue); // Read the next day line = br.readLine(); } // Build the datasets dataset.addSeries(open); dataset.addSeries(close); dataset.addSeries(low); dataset.addSeries(high); datasetOpenClose.addSeries(open); datasetOpenClose.addSeries(close); datasetHighLow.addSeries(high); datasetHighLow.addSeries(low); JFreeChart summaryChart = buildChart(dataset, "Summary", true); JFreeChart openCloseChart = buildChart(datasetOpenClose, "Open/Close Data", false); JFreeChart highLowChart = buildChart(datasetHighLow, "High/Low Data", true); JFreeChart highLowDifChart = buildDifferenceChart(datasetHighLow, "High/Low Difference Chart"); // Create this panel this.setLayout(new GridLayout(2, 2)); this.add(new ChartPanel(summaryChart)); this.add(new ChartPanel(openCloseChart)); this.add(new ChartPanel(highLowChart)); this.add(new ChartPanel(highLowDifChart)); } catch (Exception e) { e.printStackTrace(); } }
private SettingConfig generateSetting() { SettingConfig s = new SettingConfig(); s.dir = TEXT_dir.getText(); s.logBuffer = SizeType.get((String) SELECT_logBuffer.getSelectedItem()).getSize(); try { s.delay = Integer.parseInt((String) SELECT_delay.getSelectedItem()); if (s.delay < 100) s.delay = 100; } catch (Exception e) { } s.seek = CHK_seek.isSelected(); if (s.seek) { try { s.seekType = SeekType.get((String) SELECT_seekType.getSelectedItem()); } catch (Exception e) { } try { s.seekPos = Long.parseLong(TEXT_seekPos.getText()); } catch (Exception e) { } } s.charset = CharsetType.get((String) SELECT_charset.getSelectedItem()); try { s.overflowNum = Integer.parseInt(TEXT_limit.getText()); } catch (Exception e) { } s.showLineNumber = CHK_showLineNumber.isSelected(); s.softWrap = CHK_softWrap.isSelected(); return s; }
private void checkTextfile(PlainTextResource text) { Matcher m = NUMBERPATTERN.matcher(text.getText()); while (m.find()) { long nr = Long.parseLong(text.getText().substring(m.start(), m.end())); if (nr >= 0 && nr < strUsed.length) strUsed[(int) nr] = true; } }
private boolean verifyFile(File aFile, List theFileAttribList) { Iterator it = theFileAttribList.iterator(); int theIndex = 0; String theMD5 = null; String theVal = null; long theSize; while (it.hasNext()) { try { theVal = (String) it.next(); if (theIndex == 6) { theMD5 = MD5.getMD5(aFile); if (!theVal.equals(MD5.getMD5(aFile))) { return false; } break; } if (theIndex == 5) { theSize = aFile.length(); if (theSize != Long.parseLong(theVal)) { return false; } } } catch (Exception E) { E.printStackTrace(); } theIndex++; } return true; }
public void updateValues() { String snipeAtCfg = JConfig.queryConfiguration("snipemilliseconds", "30000"); String autoSubtractShipping = JConfig.queryConfiguration("snipe.subtract_shipping", "false"); long snipeAt = Long.parseLong(snipeAtCfg); snipeTime.setText(Long.toString(snipeAt / 1000)); autoSubtractShippingBox.setSelected(autoSubtractShipping.equals("true")); }
public void apply() { long newSnipeAt = Long.parseLong(snipeTime.getText()) * 1000; // Set the default snipe for everything to be whatever was typed in. JConfig.setConfiguration("snipemilliseconds", Long.toString(newSnipeAt)); JConfig.setConfiguration( "snipe.subtract_shipping", autoSubtractShippingBox.isSelected() ? "true" : "false"); }
private void downloadFile(String theFilename) { OutputStream outStream = null; InputStream is = null; try { myMessage.stateChanged("DOWNLOADLOCALBASE"); String theFile = myProperties .getProperty("BASEURL") .substring(0, myProperties.getProperty("BASEURL").lastIndexOf("/")); theFile = theFile + "/" + (new URI((theFilename).replaceAll(" ", "%20"))); URLConnection uCon = null; int size = 1024; URL Url; byte[] buf; int ByteRead, ByteWritten = 0; Url = new URL(theFile); String theLocalFilename = (String) myFileList.get(theFilename).get(2); long theFileSize = Long.parseLong((String) myFileList.get(theFilename).get(5)); outStream = new BufferedOutputStream( new FileOutputStream( myProperties.getProperty("LOCALBASEDIR") + "\\" + myFileList.get(theFilename).get(2))); uCon = Url.openConnection(); is = uCon.getInputStream(); buf = new byte[size]; while ((ByteRead = is.read(buf)) != -1) { outStream.write(buf, 0, ByteRead); ByteWritten += ByteRead; myMessage.setProgress((int) getPercentage(ByteWritten, theFileSize)); // System.out.println(ByteWritten); } myMessage.messageChanged("Downloaded Successfully."); myMessage.messageChanged( "File name:\"" + theLocalFilename + "\"\nNo ofbytes :" + ByteWritten + "Filesize =" + theFileSize); } catch (Exception e) { e.printStackTrace(); } finally { try { is.close(); outStream.close(); } catch (IOException e) { e.printStackTrace(); } } }
private void selectArrivalMouseClicked(MouseEvent e) { saveArrival.setVisible(false); saveArrival.setEnabled(false); doArrive.setVisible(true); doArrive.setEnabled(true); int row = arrivalTable.getSelectedRow(); String id = (String) arrivalTable.getValueAt(row, 0); long ID = Long.parseLong(id); arrival = entruckReceive.chooseArrival(ID); setArrivalVO(); }
void jMenuItemScheduleCommand_actionPerformed(ActionEvent e) { try { String result = JOptionPane.showInputDialog("Enter <command>,<interval>"); if (result != null) { StringTokenizer st = new StringTokenizer(result, ","); if (st.countTokens() == 2) { String command = st.nextToken(); long interval = Long.parseLong(st.nextToken()); CommandScheduler.create(command, interval * 1000); } } } catch (Exception ex) { } }
@Nullable private Long getQuickDocDelayFromGui() { String quickDocDelayAsText = myQuickDocDelayTextField.getText(); if (StringUtil.isEmptyOrSpaces(quickDocDelayAsText)) { return null; } try { long delay = Long.parseLong(quickDocDelayAsText); return delay > 0 ? delay : null; } catch (NumberFormatException e) { // Ignore incorrect value. return null; } }
/** based on http://www.exampledepot.com/egs/java.net/Post.html */ private void GetNewRobotUID() { try { // Send data URL url = new URL("http://marginallyclever.com/drawbot_getuid.php"); URLConnection conn = url.openConnection(); BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream())); robot_uid = Long.parseLong(rd.readLine()); rd.close(); } catch (Exception e) { } // did read go ok? if (robot_uid != 0) { SendLineToRobot("UID " + robot_uid); } }
private void btnGuardarActionPerformed( java.awt.event.ActionEvent evt) { // GEN-FIRST:event_btnGuardarActionPerformed gestorBitacora gestorB = new gestorBitacora(); Iterator ite = gestorH.listarClase(Viaje.class).iterator(); while (ite.hasNext()) { Viaje viaje = (Viaje) ite.next(); if (viaje.getIdViaje() == Long.parseLong(txtNumViaje.getText())) { Iterator ite1 = gestorH.listarClase(Vehiculo.class).iterator(); while (ite1.hasNext()) { Vehiculo vehiculo = (Vehiculo) ite1.next(); if (vehiculo.getDominio().equalsIgnoreCase(txtDominio.getText())) { viaje.setVehiculo(vehiculo); viaje.setEstado("Con vehiculo asignado"); gestorH.actualizarObjeto(viaje); vehiculo.setEstado("Asignado"); gestorH.actualizarObjeto(vehiculo); gestorB.cargarBitacora( String.valueOf(viaje.getIdViaje()), txtFecha.getText(), 3, labelusuario.getText(), ""); } } } } DefaultTableModel modeloT = (DefaultTableModel) tblViaje.getModel(); modeloT.setRowCount(0); gestorA.RellenarTablaViajes(tblViaje); txtNumeroSolicitud.setText(""); txtDestino.setText(""); txtCereal.setText(""); txtFechaRealizacion.setText(""); txtTipoViaje.setText(""); txtNumViaje.setText(""); txtProductor.setText(""); DefaultTableModel modelo = (DefaultTableModel) tblVehiculo.getModel(); modelo.setRowCount(0); txtVehiculo.setText(""); txtTara.setText(""); txtTipoVehiculo.setText(""); txtTransportista.setText(""); txtDominio.setText(""); JOptionPane.showMessageDialog(null, "Se asigno correctamente el vehiculo"); } // GEN-LAST:event_btnGuardarActionPerformed
public void openRbnbUri(String uri) { Pattern uriPat = Pattern.compile("^rbnb:(\\w+):(.*)$"); Matcher m = uriPat.matcher(uri); if (m.matches()) { String objType = m.group(1); String objId = m.group(2); if (objType.equalsIgnoreCase("focus")) { // Do nothing, arg handler will bring us to front anyway return; } if (objType.equalsIgnoreCase("playlist")) { long pId = Long.parseLong(objId, 16); leftSidebar.showPlaylist(pId); return; } } log.error("Received invalid rbnb uri: " + uri); }
private void generateSeekInfo() { String seekTypeStr = (String) SELECT_seekType.getSelectedItem(); SeekType seekType = SeekType.get(seekTypeStr); long pos = 0; try { pos = Long.parseLong(TEXT_seekPos.getText()); } catch (Exception e) { } String info = "Print From " + (seekType.isSeekHead() ? "HEAD" : "TAIL") + " by " + (seekType.isSeekLine() ? "Lines" : "Pos") + " at " + (seekType.isSeekLine() ? "Line" : "Pos") + " " + pos; LABEL_seek.setText(info); }
public void genSeed(ActionEvent e) { long seed = 0; boolean redo = false; do { redo = false; String seedString = JOptionPane.showInputDialog( this, "Enter a number:", Long.toString(rand.nextLong(), 36) // "Random Seed", JOptionPane.QUESTION_MESSAGE ); if (seedString == null) return; try { seed = Long.parseLong(seedString, 36); } catch (NumberFormatException ex) { JOptionPane.showMessageDialog(this, "Use only letters and numbers, max 12 characters."); redo = true; } } while (redo); genSeed(seed); }
/** * Complete the handshake, load robot-specific configuration, update the menu, repaint the preview * with the limits. * * @return true if handshake succeeds. */ public boolean ConfirmPort() { if (portConfirmed == true) return true; String hello = "HELLO WORLD! I AM DRAWBOT #"; int found = line3.lastIndexOf(hello); if (found >= 0) { portConfirmed = true; // get the UID reported by the robot String[] lines = line3.substring(found + hello.length()).split("\\r?\\n"); if (lines.length > 0) { try { robot_uid = Long.parseLong(lines[0]); } catch (NumberFormatException e) { } } // new robots have UID=0 if (robot_uid == 0) GetNewRobotUID(); mainframe.setTitle("Drawbot #" + Long.toString(robot_uid) + " connected"); // load machine specific config GetRecentPaperSize(); LoadConfig(); if (limit_top == 0 && limit_bottom == 0 && limit_left == 0 && limit_right == 0) { UpdateConfig(); } previewPane.setMachineLimits(limit_top, limit_bottom, limit_left, limit_right); SendConfig(); UpdateMenuBar(); previewPane.setConnected(true); } return portConfirmed; }
public long cacuIndex(String day) { String d = day.substring(6, 8); long index = Long.parseLong(d); return (index - 1) * 4 * FLIGHT_PER_DAY; }
// action listeners public void actionPerformed(ActionEvent e) { // doge click button gives doge if (e.getSource() == dogeClick) { cps = cps + 1; Sounds.run("wow"); // increases size of button temporarily if (animation == 0) { dogeClick.setBounds(460, 110, 80, 80); dogeClick.setIcon(new ImageIcon("Images/dogeopen.jpg")); animation = 1; } else if (animation == 1) { dogeClick.setBounds(450, 100, 100, 100); dogeClick.setIcon(new ImageIcon("Images/doge.jpg")); animation = 0; } // adds doge accordingly and updates JLabel doge = doge + ((clickUpgrade) * clickMultiply) * multiplier; dogeCount.setText("Doge: " + doge); // randomize text flavourClick.setText(flavourText[(int) (Math.random() * 49)]); flavourClick.setBounds( (int) (Math.random() * (800)), (int) ((Math.random() * (401)) + 50), getWidth(), 50); flavourClick.setFont( new Font("Comic Sans MS", Font.BOLD, (int) ((Math.random() * (15)) + 15))); Color colour = Random.getRandomColour(); flavourClick.setForeground(colour); flavourClick.setVisible(true); } // for loop for all buttons for (int i = 0; i < MAX_UPGRADES; i++) { // updates button stats and count if (e.getSource() == producers[i] && doge >= producerStats[i].getCost()) { doge = doge - producerStats[i].getCost(); producers[i].setIcon(new ImageIcon("Images//bought.PNG")); producerStats[i].increaseCount(); producerStats[i].increaseCost(); producers[i].setToolTipText( "Your " + producerStats[i].getButtonName() + " gives " + producerStats[i].getDogeProduction() * producerStats[i].getCount() + " doge per second"); dps = dps + producerStats[i].getDogeProduction(); buyProducers[i].setText( "Buy " + producerStats[i].getButtonName() + " for " + producerStats[i].getCost() + " doge"); buyDetails[i].setText( "You have: " + producerStats[i].getCount() + " " + producerStats[i].getButtonName()); } } // updates click stats and count for (int i = 0; i < MAX_CLICK; i++) { if (e.getSource() == clickers[i] && doge >= clickerStats[i].getCost()) { doge = doge - clickerStats[i].getCost(); clickerStats[i].increaseCount(); clickUpgrade = clickUpgrade + clickerStats[i].getClickBonus(); clickMultiply = clickMultiply * clickerStats[i].getClickMultiplier(); dogeClick.setToolTipText( "Each click gives you " + (clickUpgrade) * clickMultiply + " doge. wow"); clickers[i].setVisible(false); buyClickers[i].setVisible(false); } } // secret developer button in corner if (e.getSource() == devButton) { doge = doge * 2; // plays Sandstorm by Darude Sounds.run("sandstorm"); } if (e.getSource() == options) { // opens options gui Options options = new Options(); } // saves current progress into save file if (e.getSource() == save) { // opens JOtionPane Sounds.run("save"); Save temp = new Save(); String name = JOptionPane.showInputDialog("What is the name of your save file?"); temp.createOutputFile("Save//" + name + ".txt"); String producerCount = ""; String clickCount = ""; String achievementCount = ""; // adds line of code for the amount of producers for (int i = 0; i < MAX_UPGRADES; i++) { producerCount = producerCount + producerStats[i].getCount() + "|"; } // adds line of code for the amount of clickers for (int i = 0; i < MAX_CLICK; i++) { // if bought write true if (clickerStats[i].getCount() != 0) { clickCount = clickCount + "t|"; } else { // if not bought write false clickCount = clickCount + "f|"; } } // adds a line of code for achievements for (int i = 0; i < MAX_ACHIEVEMENTS; i++) { // if possess write true if (achievementStats[i].getCount() != 0) { achievementCount = achievementCount + "t|"; } else { // if do not have write f achievementCount = achievementCount + "f|"; } } // add all lines to file temp.addInfo("" + doge); temp.addInfo("" + producerCount); temp.addInfo("" + clickCount); temp.addInfo("" + achievementCount); temp.closeOutputFile(); } // opens existing save file if (e.getSource() == open) { Save temp = new Save(); String name = JOptionPane.showInputDialog("What is the name of your save file?"); temp.openInputFile("Save//" + name + ".txt"); try { // counters to open save file int add = 0; String data = ""; int producerCount = 0; int clickCount = 0; int achievementCount = 0; // turn each line into char array doge = Long.parseLong(temp.getInfo()); char producerSave[] = temp.getInfo().toCharArray(); char clickSave[] = temp.getInfo().toCharArray(); char achievementSave[] = temp.getInfo().toCharArray(); // looks at producer line and adjusts values and resets Jlabel // text for (int i = 0; i < producerSave.length; i++) { if (producerSave[i] != '|') { data = data + Character.getNumericValue(producerSave[i]); } else { // updates data in producers add = Integer.parseInt(data); producerStats[producerCount].setCount(add); producerStats[producerCount].setCost( (int) (producerStats[producerCount].getCost() * (add * producerStats[producerCount].getCostIncrease()))); buyProducers[producerCount].setText( "Buy " + producerStats[producerCount].getButtonName() + " for " + producerStats[producerCount].getCost() + " doge"); buyDetails[producerCount].setText( "You have: " + producerStats[producerCount].getCount() + " " + producerStats[producerCount].getButtonName()); producers[producerCount].setToolTipText( "Your " + producerStats[producerCount].getButtonName() + " gives " + producerStats[producerCount].getDogeProduction() * producerStats[producerCount].getCount() + " doge per second"); dps = dps + (producerStats[producerCount].getDogeProduction() * producerStats[producerCount].getCount()); data = ""; producerCount++; add = 0; } } // reads clicker upgrades saves for (int i = 0; i < MAX_CLICK * 2; i++) { if (clickSave[i] == 't') { // updates data in clickers clickerStats[clickCount].setCount(1); clickUpgrade = (clickUpgrade + clickerStats[clickCount].getClickBonus()) * clickerStats[clickCount].getClickMultiplier(); dogeClick.setToolTipText("Each click gives you " + clickUpgrade + " doge. wow"); clickers[clickCount].setVisible(false); buyClickers[clickCount].setVisible(false); clickCount++; } else if (clickSave[i] == 'f') { clickCount++; } } // reads achievement lines for (int i = 0; i < MAX_ACHIEVEMENTS * 2; i++) { if (achievementSave[i] == 't') { // updates achievements achievementStats[achievementCount].setCount(1); achievements[achievementCount].setVisible(true); achievementCount++; } else if (achievementSave[i] == 'f') { achievementCount++; } } dogeCount.setText("Doge: " + doge); } catch (IOException e1) { // access invalid file e1.printStackTrace(); System.out.println("Invalid file!"); } // closes input file try { temp.closeInputFile(); } catch (IOException e1) { // access invalid file e1.printStackTrace(); System.out.println("Invalid file!"); } } }
/** * Load VCS roots * * @param project the project * @param roots the VCS root list * @param exceptions the list of of exceptions to use * @param fetchData if true, the data for remote is fetched. * @return the loaded information about vcs roots */ private static List<Root> loadRoots( final Project project, final List<VirtualFile> roots, final Collection<VcsException> exceptions, final boolean fetchData) { final ArrayList<Root> rc = new ArrayList<Root>(); for (VirtualFile root : roots) { try { Root r = new Root(); rc.add(r); r.root = root; GitBranch b = GitBranch.current(project, root); if (b != null) { r.currentBranch = b.getFullName(); r.remoteName = b.getTrackedRemoteName(project, root); r.remoteBranch = b.getTrackedBranchName(project, root); if (r.remoteName != null) { if (fetchData && !r.remoteName.equals(".")) { GitLineHandler fetch = new GitLineHandler(project, root, GitCommand.FETCH); fetch.addParameters(r.remoteName, "-v"); Collection<VcsException> exs = GitHandlerUtil.doSynchronouslyWithExceptions(fetch); exceptions.addAll(exs); } GitBranch tracked = b.tracked(project, root); assert tracked != null : "Tracked branch cannot be null here"; final boolean trackedBranchExists = tracked.exists(root); if (!trackedBranchExists) { LOG.info("loadRoots tracked branch " + tracked + " doesn't exist yet"); } // check what remote commits are not yet merged if (trackedBranchExists) { GitSimpleHandler toPull = new GitSimpleHandler(project, root, GitCommand.LOG); toPull.addParameters( "--pretty=format:%H", r.currentBranch + ".." + tracked.getFullName()); toPull.setNoSSH(true); toPull.setStdoutSuppressed(true); StringScanner su = new StringScanner(toPull.run()); while (su.hasMoreData()) { if (su.line().trim().length() != 0) { r.remoteCommits++; } } } // check what local commits are to be pushed GitSimpleHandler toPush = new GitSimpleHandler(project, root, GitCommand.LOG); // if the tracked branch doesn't exist yet (nobody pushed the branch yet), show all // commits on this branch. final String revisions = trackedBranchExists ? tracked.getFullName() + ".." + r.currentBranch : r.currentBranch; toPush.addParameters("--pretty=format:%H%x20%ct%x20%at%x20%s%n%P", revisions); toPush.setNoSSH(true); toPush.setStdoutSuppressed(true); StringScanner sp = new StringScanner(toPush.run()); while (sp.hasMoreData()) { if (sp.isEol()) { sp.line(); continue; } Commit c = new Commit(); c.root = r; String hash = sp.spaceToken(); String time = sp.spaceToken(); c.revision = new GitRevisionNumber(hash, new Date(Long.parseLong(time) * 1000L)); c.authorTime = sp.spaceToken(); c.message = sp.line(); c.isMerge = sp.line().indexOf(' ') != -1; r.commits.add(c); } } } } catch (VcsException e) { exceptions.add(e); } } return rc; }
@Override public void run() { try { // Create data input and output streams DataInputStream inputFromClient = new DataInputStream(socket.getInputStream()); DataOutputStream outputToClient = new DataOutputStream(socket.getOutputStream()); // Set up a byte buffer to capture the file from the client byte[] buffer = new byte[BUFFER_SIZE]; OutputStream outputStream = null; String fileName = ""; boolean createFile = true; int bytesReceived = 0; long totalBytesReceived = 0; long fileSize = 0; // Continuously serve the client while (true) { bytesReceived = inputFromClient.read(buffer); if (bytesReceived > 0) { // Get the file transmission header from the initial client packet String transmitHeader = new String(buffer, 0, bytesReceived); // transmitHeader = transmitHeader.substring(0, bytesReceived).trim().; String[] header = transmitHeader.split(HEADER_DEL); fileSize = Long.parseLong(header[0]); fileName = header[1]; // Send receipt acknowledgment back to the client. Just send back the number of bytes // received. outputToClient.writeInt(bytesReceived); // Reinitialize buffer values buffer = new byte[BUFFER_SIZE]; bytesReceived = 0; } // Wait for client to send bytes while ((bytesReceived = inputFromClient.read(buffer)) != -1) { if (inputFromClient.available() > 0) { if (createFile) { // Get a unique name for the file to be received fileName = textFolder.getText() + fileName; // getUniqueFileName(); outputStream = createFile(fileName); createFile = false; textArea.append("Receiving file from client.\n"); } // Write bytes to file outputStream.write(buffer, 0, bytesReceived); } else { // We get here if no more data is available, but some bytes were already // received // If bytes were received and the file wasn't already created, // it means that the file was smaller than our buffer size. // Create the file... if (bytesReceived > 0 && createFile) { // Get a unique name for the file to be received fileName = textFolder.getText() + fileName; // getUniqueFileName(); outputStream = createFile(fileName); createFile = false; textArea.append("Receiving file from client.\n"); } if (outputStream != null) { if (bytesReceived > 0) { // Write remaining bytes to file, if any outputStream.write(buffer, 0, bytesReceived); } outputStream.flush(); outputStream.close(); textArea.append("Received file successfully. Saved as " + fileName + "\n"); // Return success to client. outputToClient.writeInt(0); } // Reset creation flag createFile = true; break; } // Reinitialize buffer values buffer = new byte[BUFFER_SIZE]; bytesReceived = 0; } } } catch (IOException e) { System.err.println(e); } }
@Override public void run() { try { // Create a packet for sending data DatagramPacket sendPacket = new DatagramPacket(buffer, buffer.length); OutputStream outputStream = null; String fileName = ""; boolean createFile = true; int bytesReceived = 0; long totalBytesReceived = 0; long fileSize = 0; socket.receive(receivePacket); // Display the client number textArea.append("Starting thread for UDP client " + clientNo + " at " + new Date() + '\n'); textArea.append( "The client host name is " + receivePacket.getAddress().getHostName() + " and port number is " + receivePacket.getPort() + '\n'); // Continuously serve the client while (true) { bytesReceived = receivePacket.getLength(); if (bytesReceived > 0) { // Get the file transmission header from the initial client packet String transmitHeader = new String(receivePacket.getData(), 0, bytesReceived); // transmitHeader = transmitHeader.substring(0, bytesReceived).trim().; String[] header = transmitHeader.split(HEADER_DEL); fileSize = Long.parseLong(header[0]); fileName = header[1]; // Send receipt acknowledgment back to the client. Just send back the number of bytes // received. setSendPacketAddress(sendPacket, receivePacket); sendPacket.setData(String.valueOf(bytesReceived).getBytes()); socket.send(sendPacket); } while (totalBytesReceived < fileSize) { // Wait for client to send bytes // socket.setSendBufferSize(BUFFER_SIZE); socket.receive(receivePacket); bytesReceived = receivePacket.getLength(); if (totalBytesReceived == 0) { if (createFile) { // Get a unique name for the file to be received // fileName = getUniqueFileName(); fileName = textFolder.getText() + fileName; outputStream = createFile(fileName); createFile = false; textArea.append("Receiving file from client.\n"); } // Write bytes to file outputStream.write(receivePacket.getData(), 0, bytesReceived); } else { if (outputStream != null) { // Write bytes to file, if any outputStream.write(receivePacket.getData(), 0, bytesReceived); } } // Increment total bytes received totalBytesReceived += bytesReceived; // Tell the client to send more data. Just send back the number of bytes received. sendPacket.setData(String.valueOf(bytesReceived).getBytes()); socket.send(sendPacket); // buffer = new byte[BUFFER_SIZE]; Arrays.fill(buffer, (byte) 0); receivePacket = new DatagramPacket(buffer, buffer.length); } outputStream.flush(); outputStream.close(); textArea.append("Received file successfully. Saved as " + fileName + "\n"); // Tell the client transmission is complete. Just send back the total number of bytes // received. sendPacket.setData(String.valueOf(totalBytesReceived).getBytes()); socket.send(sendPacket); // Reset creation flag createFile = true; totalBytesReceived = 0; // Wait for client to send another file socket.receive(receivePacket); } } catch (IOException e) { System.err.println(e); } }
public void InsertDataTable() { for (int i = 0; i < dataBaru.size(); i++) { try { rowSet.moveToInsertRow(); for (int ii = 0; ii < insertKolom.size(); ii++) { String temp = insertKolom.get(ii + ""); String data[] = temp.split("#"); int no = 0; boolean constanta = false; if (data[1].trim().toLowerCase().equals("c")) { constanta = true; } else { try { no = Integer.parseInt(data[1].trim()); } catch (Exception e) { no = 0; } } if (data[0].trim().toLowerCase().contains("i")) { if (data[2].trim().toLowerCase().equals("boolean")) { String value = ""; if (data[4].trim().toLowerCase().equals("int")) { if (getValueAt( new Integer(dataBaru.get(i).toString()), Integer.parseInt(data[1].trim())) .toString() .equals("true")) { if (data[5].trim().equals("1") || data[5].trim().equals("0")) { value = "1"; } else { value = "Y"; } } else { if (data[5].trim().equals("1") || data[5].trim().equals("0")) { value = "0"; } else { value = "N"; } } try { rowSet.updateInt(data[3].trim().toString(), Integer.parseInt(value)); } catch (Exception e) { e.printStackTrace(); } } else { if (getValueAt( new Integer(dataBaru.get(i).toString()), Integer.parseInt(data[1].trim())) .toString() .equals("true")) { if (data[5].trim().equals("1") || data[5].trim().equals("0")) { value = "1"; } else { value = "Y"; } } else { if (data[5].trim().equals("1") || data[5].trim().equals("0")) { value = "0"; } else { value = "N"; } } try { rowSet.updateString(data[3].trim().toString(), value.trim()); } catch (Exception e) { e.printStackTrace(); } } } else if (data[2].trim().toLowerCase().equals("date")) { String value = ""; java.util.Date dd = (java.util.Date) getValueAt(new Integer(dataBaru.get(i).toString()), no); if (data[4].equals("dd-MM-yyyy")) { value = Function.dateToString(dd); } else if (data[4].equals("MM-yyyy")) { value = Function.monthToString(dd).trim(); } else if (data[4].equals("yyyy")) { // value = Function.yearToDate(sql); JOptionPane.showMessageDialog(null, "Belom Support"); } // JOptionPane.showMessageDialog(null, value.length()); try { rowSet.updateString(data[3].trim().toString(), value.trim()); } catch (Exception e) { e.printStackTrace(); } } else if (data[2].trim().toLowerCase().equals("string") || data[2].trim().toLowerCase().equals("numeric")) { String value = ""; if (constanta) { value = data[6].trim(); } else { try { value = getValueAt(new Integer(dataBaru.get(i).toString()), no).toString(); } catch (Exception e) { try { value = getValueAt(new Integer(dataBaru.get(i).toString()), no).toString(); } catch (Exception ee) { value = ""; } } } if (data[4].trim().toLowerCase().equals("int")) { try { if (value.trim().equals("")) { value = "0"; } rowSet.updateLong(data[3].trim().toString(), Long.parseLong(value.trim())); } catch (Exception e) { e.printStackTrace(); } } else { try { rowSet.updateString(data[3].trim().toString(), value.trim()); } catch (Exception e) { e.printStackTrace(); } } } else if (data[2].trim().toLowerCase().equals("combo")) { String value = ""; String valueKolom = ""; try { valueKolom = getValueAt(new Integer(dataBaru.get(i).toString()), no).toString().trim(); } catch (Exception e) { valueKolom = ""; } try { value = Function.getValueFromCell(data[5].trim(), valueKolom); } catch (Exception e) { value = ""; } if (data[4].trim().toLowerCase().equals("int")) { try { rowSet.updateString(data[3].trim().toString(), value.trim()); } catch (Exception e) { e.printStackTrace(); } } else { try { rowSet.updateString(data[3].trim().toString(), value.trim()); } catch (Exception e) { e.printStackTrace(); } } } } } // JOptionPane.showMessageDialog(null, rowSet.getCommand()); rowSet.insertRow(); } catch (Exception e) { e.printStackTrace(); } } }
public void updateDataTable() { for (int i = 0; i < dataAsli.size(); i++) { try { rowSet.absolute(new Integer(dataAsli.elementAt(i).toString())); if (rowSet.next()) { for (int ii = 0; ii < updateKolom.size(); ii++) { String temp = updateKolom.get(ii + ""); String data[] = temp.split("#"); int no = 0; try { no = Integer.parseInt(data[1].trim()); } catch (Exception e) { no = 0; } if (data[0].trim().toLowerCase().contains("u")) { if (data[2].trim().toLowerCase().equals("boolean")) { String value = ""; if (data[4].trim().toLowerCase().equals("int")) { if (getValueAt( new Integer(dataAsli.get(i).toString()), Integer.parseInt(data[1].trim())) .toString() .equals("true")) { if (data[5].trim().equals("1") || data[5].trim().equals("0")) { value = "1"; } else { value = "Y"; } } else { if (data[5].trim().equals("1") || data[5].trim().equals("0")) { value = "0"; } else { value = "N"; } } try { rowSet.updateInt(data[3].trim().toString(), Integer.parseInt(value)); } catch (Exception e) { e.printStackTrace(); } } else { if (getValueAt( new Integer(dataAsli.get(i).toString()), Integer.parseInt(data[1].trim())) .toString() .equals("true")) { if (data[5].trim().equals("1") || data[5].trim().equals("0")) { value = "1"; } else { value = "Y"; } } else { if (data[5].trim().equals("1") || data[5].trim().equals("0")) { value = "0"; } else { value = "N"; } } try { rowSet.updateString(data[3].trim().toString(), value.trim()); } catch (Exception e) { e.printStackTrace(); } } } else if (data[2].trim().toLowerCase().equals("date")) { String value = ""; java.util.Date dd = (java.util.Date) getValueAt(new Integer(dataAsli.get(i).toString()), no); if (data[4].equals("dd-MM-yyyy")) { value = Function.dateToString(dd); } else if (data[4].equals("MM-yyyy")) { value = Function.monthToString(dd); } else if (data[4].equals("yyyy")) { // value = Function.yearToDate(sql); JOptionPane.showMessageDialog(null, "Belom Support"); } try { rowSet.updateString(data[3].trim().toString(), value.trim()); } catch (Exception e) { e.printStackTrace(); } } else if (data[2].trim().toLowerCase().equals("string") || data[2].trim().toLowerCase().equals("numeric")) { String value = ""; String data1 = data[1].trim(); if (data1 == null || data1.equals("")) { data1 = "0"; } try { value = getValueAt(new Integer(dataAsli.get(i).toString()), no).toString(); } catch (Exception e) { // e.printStackTrace(); try { value = getValueAt(new Integer(dataAsli.get(i).toString()), no).toString(); } catch (Exception ee) { value = ""; // e.printStackTrace(); } } if (data[4].trim().toLowerCase().equals("int")) { try { if (value.trim().equals("")) { value = "0"; } rowSet.updateLong(data[3].trim().toString(), Long.parseLong(value.trim())); } catch (Exception e) { e.printStackTrace(); } } else { try { rowSet.updateString(data[3].trim().toString(), value.trim()); } catch (Exception e) { e.printStackTrace(); } } } else if (data[2].trim().toLowerCase().equals("combo")) { String value = ""; value = Function.getValueFromCell( data[5].trim(), getValueAt(new Integer(dataAsli.get(i).toString()), no).toString().trim()); if (data[4].trim().toLowerCase().equals("int")) { try { rowSet.updateString(data[3].trim().toString(), value.trim()); } catch (Exception e) { e.printStackTrace(); } } else { try { rowSet.updateString(data[3].trim().toString(), value.trim()); } catch (Exception e) { e.printStackTrace(); } } } } } rowSet.updateRow(); } } catch (Exception e) { e.printStackTrace(); } } }
private void searchListMouseClicked(MouseEvent e) { String id = deliveryID.getText(); long num = Long.parseLong(id); getDeliveryList(num); }
public void get_wallet_balance() { // ********************** System.out.println("Get Balance..."); rpcurl = lm.carbon_settings[10]; rpcaddress = lm.rpcaddress_confirm; rpcuser = lm.carbon_settings[12]; rpcpassword = lm.carbon_settings[13]; System.out.println(rpcuser); System.out.println(rpcpassword); System.out.println(rpcaddress); String line = new String(); String line2 = new String(); String url1 = new String( "https://blockchain.info/merchant/" + rpcuser + "/address_balance?password="******"&address=" + rpcaddress + "&confirmations=6"); try { // Sets the authenticator that will be used by the networking code // when a proxy or an HTTP server asks for authentication. // Authenticator.setDefault(new CustomAuthenticator()); System.out.println("GO0"); URL url = new URL(url1); HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(); System.out.println("GO1"); // read text returned by server BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream())); // BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream())); // BufferedReader in = new BufferedReader(null); while ((line = in.readLine()) != null) { System.out.println(line); line2 = line2 + line; } in.close(); JSONParser parser = new JSONParser(); try { Object obj = parser.parse(line2); JSONObject jsonObject = (JSONObject) obj; String address = (String) jsonObject.get("address"); System.out.println(address); String balance = (String) jsonObject.get("balance").toString(); System.out.println(balance); lm.wallet_value_confirm = (long) Long.parseLong(balance); System.out.println("lm.wallet_value_confirm " + lm.wallet_value_confirm); } // try catch (ParseException e) { e.printStackTrace(); } } // try catch (MalformedURLException e) { System.out.println("Malformed URL: " + e.getMessage()); } catch (IOException e) { System.out.println("I/O Error: " + e.getMessage()); } catch (Exception e) { System.out.println(e.getMessage()); } } // ***************test_for_sales()
@SuppressWarnings("UseJBColor") private static Color parseColor(final String colorString) { final long rgb = Long.parseLong(colorString, 16); return new Color((int) rgb, rgb > 0xffffff); }