List of usage examples for java.lang System arraycopy
@HotSpotIntrinsicCandidate public static native void arraycopy(Object src, int srcPos, Object dest, int destPos, int length);
From source file:TableSetDataEvent.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setLayout(new FillLayout()); final Table table = new Table(shell, SWT.BORDER | SWT.VIRTUAL); table.addListener(SWT.SetData, new Listener() { public void handleEvent(Event e) { System.out.println(e); TableItem item = (TableItem) e.item; int index = table.indexOf(item); item.setText("Item " + data[index]); }/*w w w.j av a2 s . com*/ }); int count = 0; Random random = new Random(); while (count++ < 50) { int grow = 10; int[] newData = new int[data.length + grow]; System.arraycopy(data, 0, newData, 0, data.length); int index = data.length; data = newData; for (int j = 0; j < grow; j++) { data[index++] = random.nextInt(); } table.setItemCount(data.length); table.clearAll(); } shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:org.eclipse.swt.snippets.Snippet151.java
public static void main(String[] args) { final Display display = new Display(); Shell shell = new Shell(display); shell.setText("Snippet 151"); shell.setLayout(new FillLayout()); final Table table = new Table(shell, SWT.BORDER | SWT.VIRTUAL); table.addListener(SWT.SetData, e -> { TableItem item = (TableItem) e.item; int index = table.indexOf(item); item.setText("Item " + data[index]); });//w ww . j a v a 2 s . c o m Thread thread = new Thread() { @Override public void run() { int count = 0; Random random = new Random(); while (count++ < 500) { if (table.isDisposed()) return; // add 10 random numbers to array and sort int grow = 10; int[] newData = new int[data.length + grow]; System.arraycopy(data, 0, newData, 0, data.length); int index = data.length; data = newData; for (int j = 0; j < grow; j++) { data[index++] = random.nextInt(); } Arrays.sort(data); display.syncExec(() -> { if (table.isDisposed()) return; table.setItemCount(data.length); table.clearAll(); }); try { Thread.sleep(500); } catch (Throwable t) { } } } }; thread.start(); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:boa.BoaMain.java
public static void main(final String[] args) throws IOException { final Options options = new Options(); options.addOption("p", "parse", false, "parse and semantic check a Boa program (don't generate code)"); options.addOption("c", "compile", false, "compile a Boa program"); options.addOption("e", "execute", false, "execute a Boa program locally"); options.addOption("g", "generate", false, "generate a Boa dataset"); try {// w ww. j a v a2 s . c o m if (args.length == 0) { printHelp(options, null); return; } else { final CommandLine cl = new PosixParser().parse(options, new String[] { args[0] }); final String[] tempargs = new String[args.length - 1]; System.arraycopy(args, 1, tempargs, 0, args.length - 1); if (cl.hasOption("c")) { boa.compiler.BoaCompiler.main(tempargs); } else if (cl.hasOption("p")) { boa.compiler.BoaCompiler.parseOnly(tempargs); } else if (cl.hasOption("e")) { boa.evaluator.BoaEvaluator.main(tempargs); } else if (cl.hasOption("g")) { boa.datagen.BoaGenerator.main(tempargs); } } } catch (final org.apache.commons.cli.ParseException e) { printHelp(options, e.getMessage()); } }
From source file:Ch7_Images.java
public static void main(String[] args) { int numRows = 6, numCols = 11, pix = 20; PaletteData pd = new PaletteData( new RGB[] { new RGB(0x00, 0x00, 0x00), new RGB(0x80, 0x80, 0x80), new RGB(0xFF, 0xFF, 0xFF) }); ImageData[] flagArray = new ImageData[3]; for (int frame = 0; frame < flagArray.length; frame++) { flagArray[frame] = new ImageData(pix * numCols, pix * numRows, 4, pd); flagArray[frame].delayTime = 10; for (int x = 0; x < pix * numCols; x++) { for (int y = 0; y < pix * numRows; y++) { int value = (((x / pix) % 3) + (3 - ((y / pix) % 3)) + frame) % 3; flagArray[frame].setPixel(x, y, value); }//from www . jav a2 s. c o m } } ImageLoader gifloader = new ImageLoader(); ByteArrayOutputStream flagByte[] = new ByteArrayOutputStream[3]; byte[][] gifarray = new byte[3][]; gifloader.data = flagArray; for (int i = 0; i < 3; i++) { flagByte[i] = new ByteArrayOutputStream(); flagArray[0] = flagArray[i]; gifloader.save(flagByte[i], SWT.IMAGE_GIF); gifarray[i] = flagByte[i].toByteArray(); } byte[] gif = new byte[4628]; System.arraycopy(gifarray[0], 0, gif, 0, 61); System.arraycopy(new byte[] { 33, (byte) 255, 11 }, 0, gif, 61, 3); System.arraycopy("NETSCAPE2.0".getBytes(), 0, gif, 64, 11); System.arraycopy(new byte[] { 3, 1, -24, 3, 0, 33, -7, 4, -24 }, 0, gif, 75, 9); System.arraycopy(gifarray[0], 65, gif, 84, 1512); for (int i = 1; i < 3; i++) { System.arraycopy(gifarray[i], 61, gif, 1516 * i + 80, 3); gif[1516 * i + 83] = (byte) -24; System.arraycopy(gifarray[i], 65, gif, 1516 * i + 84, 1512); } try { DataOutputStream in = new DataOutputStream( new BufferedOutputStream(new FileOutputStream(new File("FlagGIF.gif")))); in.write(gif, 0, gif.length); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Security.addProvider(new BouncyCastleProvider()); SecureRandom random = new SecureRandom(); IvParameterSpec ivSpec = createCtrIvForAES(1, random); Key key = createKeyForAES(256, random); Cipher cipher = Cipher.getInstance("AES/CTR/NoPadding", "BC"); String input = "www.java2s.com"; Mac mac = Mac.getInstance("DES", "BC"); byte[] macKeyBytes = "12345678".getBytes(); Key macKey = new SecretKeySpec(macKeyBytes, "DES"); System.out.println("input : " + input); // encryption step cipher.init(Cipher.ENCRYPT_MODE, key, ivSpec); byte[] cipherText = new byte[cipher.getOutputSize(input.length() + mac.getMacLength())]; int ctLength = cipher.update(input.getBytes(), 0, input.length(), cipherText, 0); mac.init(macKey);//from ww w.j a va 2 s. c o m mac.update(input.getBytes()); ctLength += cipher.doFinal(mac.doFinal(), 0, mac.getMacLength(), cipherText, ctLength); System.out.println("cipherText : " + new String(cipherText)); // decryption step cipher.init(Cipher.DECRYPT_MODE, key, ivSpec); byte[] plainText = cipher.doFinal(cipherText, 0, ctLength); int messageLength = plainText.length - mac.getMacLength(); mac.init(macKey); mac.update(plainText, 0, messageLength); byte[] messageHash = new byte[mac.getMacLength()]; System.arraycopy(plainText, messageLength, messageHash, 0, messageHash.length); System.out.println("plain : " + new String(plainText) + " verified: " + MessageDigest.isEqual(mac.doFinal(), messageHash)); }
From source file:com.rover12421.shaka.cli.Main.java
public static void main(String[] args) throws Exception { boolean smali = false; boolean baksmali = false; String[] realyArgs = args;/*from w ww .j a v a2 s.c om*/ if (args.length > 0) { String cmd = args[0]; if (cmd.equalsIgnoreCase("s") || cmd.equalsIgnoreCase("smali")) { smali = true; } else if (cmd.equalsIgnoreCase("bs") || cmd.equalsIgnoreCase("baksmali")) { baksmali = true; } if (smali || baksmali) { realyArgs = new String[args.length - 1]; System.arraycopy(args, 1, realyArgs, 0, realyArgs.length); } } // cli parser CommandLineParser parser = new IgnoreUnkownArgsPosixParser(); CommandLine commandLine; Option language = CommandLineArgEnum.LANGUAGE.getOption(); Options options = new Options(); options.addOption(language); try { commandLine = parser.parse(options, args, false); if (CommandLineArgEnum.LANGUAGE.hasMatch(commandLine)) { String lngStr = commandLine.getOptionValue(CommandLineArgEnum.LANGUAGE.getOpt()); Locale locale = Locale.forLanguageTag(lngStr); if (locale.toString().isEmpty()) { lngStr = lngStr.replaceAll("_", "-"); locale = Locale.forLanguageTag(lngStr); } MultiLanguageSupport.getInstance().setLang(locale); } } catch (Exception ex) { } if (smali) { smaliMainAj.setHookMain(ApktoolMainAj.getHookMain()); org.jf.smali.main.main(realyArgs); } else if (baksmali) { baksmaliMainAj.setHookMain(ApktoolMainAj.getHookMain()); org.jf.baksmali.main.main(realyArgs); } else { brut.apktool.Main.main(realyArgs); } }
From source file:org.eclipse.swt.snippets.Snippet80.java
public static void main(String[] args) { final Display display = new Display(); final Shell shell = new Shell(display); shell.setText("Snippet 80"); shell.setLayout(new FillLayout()); final Tree tree = new Tree(shell, SWT.BORDER | SWT.MULTI); for (int i = 0; i < 2; i++) { TreeItem item = new TreeItem(tree, SWT.NONE); item.setText("item " + i); for (int j = 0; j < 2; j++) { TreeItem subItem = new TreeItem(item, SWT.NONE); subItem.setText("item " + j); for (int k = 0; k < 2; k++) { TreeItem subsubItem = new TreeItem(subItem, SWT.NONE); subsubItem.setText("item " + k); }//from w w w . ja va 2s.c om } } tree.addSelectionListener(widgetSelectedAdapter(e -> { TreeItem[] selection = tree.getSelection(); TreeItem[] revisedSelection = new TreeItem[0]; for (int i = 0; i < selection.length; i++) { String text = selection[i].getText(); if (text.indexOf('1') > 0) { TreeItem[] newSelection = new TreeItem[revisedSelection.length + 1]; System.arraycopy(revisedSelection, 0, newSelection, 0, revisedSelection.length); newSelection[revisedSelection.length] = selection[i]; revisedSelection = newSelection; } } tree.setSelection(revisedSelection); })); shell.setSize(300, 300); shell.open(); while (!shell.isDisposed()) { if (!display.readAndDispatch()) display.sleep(); } display.dispose(); }
From source file:jetbrains.exodus.util.ForkedProcessRunner.java
@SuppressWarnings({ "HardcodedFileSeparator" }) public static void main(String[] args) throws Exception { log.info("Process started. Arguments: " + Arrays.toString(args)); if (args.length < 2) { exit("Arguments do not contain port number and/or class to be run. Exit.", null); }//from www . j a va 2 s. co m try { int port = Integer.parseInt(args[0]); socket = new Socket("localhost", port); streamer = new Streamer(socket); } catch (NumberFormatException e) { exit("Failed to parse port number: " + args[0] + ". Exit.", null); } ForkedLogic forkedLogic = null; try { Class<?> clazz = Class.forName(args[1]); forkedLogic = (ForkedLogic) clazz.getConstructor().newInstance(); } catch (Exception e) { exit("Failed to instantiate or initialize ForkedLogic descendant", e); } // lets provide the peer with our process id streamer.writeString(getProcessId()); String[] realArgs = new String[args.length - 2]; System.arraycopy(args, 2, realArgs, 0, realArgs.length); forkedLogic.forked(realArgs); }
From source file:Blobs.java
public static void main(String args[]) { if (args.length != 1) { System.err.println("Syntax: <java Blobs [driver] [url] " + "[uid] [pass] [file]"); return;/*from w w w . j av a 2 s. co m*/ } try { Class.forName(args[0]).newInstance(); Connection con = DriverManager.getConnection(args[1], args[2], args[3]); File f = new File(args[4]); PreparedStatement stmt; if (!f.exists()) { // if the file does not exist // retrieve it from the database and write it to the named file ResultSet rs; stmt = con.prepareStatement("SELECT blobData " + "FROM BlobTest " + "WHERE fileName = ?"); stmt.setString(1, args[0]); rs = stmt.executeQuery(); if (!rs.next()) { System.out.println("No such file stored."); } else { Blob b = rs.getBlob(1); BufferedOutputStream os; os = new BufferedOutputStream(new FileOutputStream(f)); os.write(b.getBytes(0, (int) b.length()), 0, (int) b.length()); os.flush(); os.close(); } } else { // otherwise read it and save it to the database FileInputStream fis = new FileInputStream(f); byte[] tmp = new byte[1024]; byte[] data = null; int sz, len = 0; while ((sz = fis.read(tmp)) != -1) { if (data == null) { len = sz; data = tmp; } else { byte[] narr; int nlen; nlen = len + sz; narr = new byte[nlen]; System.arraycopy(data, 0, narr, 0, len); System.arraycopy(tmp, 0, narr, len, sz); data = narr; len = nlen; } } if (len != data.length) { byte[] narr = new byte[len]; System.arraycopy(data, 0, narr, 0, len); data = narr; } stmt = con.prepareStatement("INSERT INTO BlobTest(fileName, " + "blobData) VALUES(?, ?)"); stmt.setString(1, args[0]); stmt.setObject(2, data); stmt.executeUpdate(); f.delete(); } con.close(); } catch (Exception e) { e.printStackTrace(); } }
From source file:biospectra.BioSpectra.java
/** * @param args the command line arguments *//*from w ww. j a v a 2 s .co m*/ public static void main(String[] args) throws Exception { if (args.length < 1) { printHelp(); return; } String programMode = args[0]; String[] programArgs = new String[args.length - 1]; System.arraycopy(args, 1, programArgs, 0, args.length - 1); if (programMode.equalsIgnoreCase("i") || programMode.equalsIgnoreCase("index")) { System.out.println("Indexing..."); CommandArgumentsParser<CommandArgumentIndex> parser = new CommandArgumentsParser<CommandArgumentIndex>(); CommandArgumentIndex indexArg = new CommandArgumentIndex(); if (!parser.parse(programArgs, indexArg)) { return; } index(indexArg); } else if (programMode.equalsIgnoreCase("lc") || programMode.equalsIgnoreCase("lclassify")) { System.out.println("Classifying (LOCAL mode)..."); CommandArgumentsParser<CommandArgumentLocalClassifier> parser = new CommandArgumentsParser<CommandArgumentLocalClassifier>(); CommandArgumentLocalClassifier classifierArg = new CommandArgumentLocalClassifier(); if (!parser.parse(programArgs, classifierArg)) { return; } classifyLocal(classifierArg); } else if (programMode.equalsIgnoreCase("rc") || programMode.equalsIgnoreCase("rclassify")) { System.out.println("Classifying (REMOTE mode)..."); CommandArgumentsParser<CommandArgumentClassifierClient> parser = new CommandArgumentsParser<CommandArgumentClassifierClient>(); CommandArgumentClassifierClient clientArg = new CommandArgumentClassifierClient(); if (!parser.parse(programArgs, clientArg)) { return; } classifyRemote(clientArg); } else if (programMode.equalsIgnoreCase("svr") || programMode.equalsIgnoreCase("server")) { System.out.println("Running a classification server..."); CommandArgumentsParser<CommandArgumentServer> parser = new CommandArgumentsParser<CommandArgumentServer>(); CommandArgumentServer serverArg = new CommandArgumentServer(); if (!parser.parse(programArgs, serverArg)) { return; } runServer(serverArg); } else if (programMode.equalsIgnoreCase("simulate")) { System.out.println("Generating simulated reads..."); simulateReads(programArgs); } else { printHelp(); } }