public static void main(String arg[]) throws Exception{ boolean failure = false; for (Provider p: Security.getProviders()) { System.out.print(p.getName() + " "); if (p.getVersion() != 10.0d) { System.out.println("failed. " + "Version received was " + p.getVersion()); failure = true; } else { System.out.println("passed."); } } if (failure) { throw new Exception("Provider(s) failed to have the expected " + "version value."); } }
@Test public void testDataset() { ObjectNode inputJson = Json.newObject(); inputJson.put("dataset_uri", "dalids:///feedimpressionevent_mp/feedimpressionevent"); try { ObjectNode resultNode = DatasetDao.getDatasetDependency( inputJson); assertThat(resultNode.isContainerNode()); } catch (Exception e) { assertThat(false); } }
private void implTestIfReachable(FileObject fo) throws Exception { URL urlFromMapper = URLMapper.findURL(fo, getURLType()); if (isNullURLExpected(urlFromMapper, fo)) return; assertNotNull(urlFromMapper); URLConnection fc = urlFromMapper.openConnection(); if (fc instanceof JarURLConnection && fo.isFolder()) return; InputStream ic = fc.getInputStream(); try { assertNotNull(ic); } finally { if (ic != null) ic.close(); } }
public void testMetodoInserir() { Pais pais = new Pais(); pais.setNome("Brasil"); try { PaisBO paisBO = new PaisBO(); paisBO.inserir(pais); Estado estado = new Estado(); estado.setNome("Goiás"); estado.setPais(pais); EstadoBO estadoBO = new EstadoBO(); estadoBO.inserir(estado); }catch (Exception ex) { fail("Falha ao inserir um estado: " + ex.getMessage()); } }
public void verifyMultiSequential_NoSideEffect() throws Exception{ StringCB scb = new StringCB(zk); scb.verifyCreate(); String path = scb.path + "-"; String seqPath = path + "0000000002"; zk.create(path, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); Assert.assertNotNull(zk.exists(path + "0000000001", false)); List<Op> ops = Arrays.asList( Op.create(path , new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL), Op.delete("/nonexist", -1)); zk.multi(ops, this, null); latch_await(); Assert.assertNull(zk.exists(seqPath, false)); zk.create(path, new byte[0], Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT_SEQUENTIAL); Assert.assertNotNull(zk.exists(seqPath, false)); }
/** * locateLocaleSpecificFileInClassPath returns a DataInputStream that * can be used to read the requested file, but the name of the file is * determined using information from the current locale and the supplied * file name (which is treated as a "base" name, and is supplemented with * country and language related suffixes, obtained from the current * locale). The CLASSPATH is used to locate the file. * * @param fileName The name of the file to locate. The file name * may be qualified with a partial path name, using '/' as the separator * character or using separator characters appropriate for the host file * system, in which case each directory or zip file in the CLASSPATH will * be used as a base for finding the fully-qualified file. * Here is an example of how the supplied fileName is used as a base * for locating a locale-specific file: * * <pre> * Supplied fileName: a/b/c/x.y, current locale: US English * * Look first for: a/b/c/x_en_US.y * (if that fails) Look next for: a/b/c/x_en.y * (if that fails) Look last for: a/b/c/x.y * * All elements of the class path are searched for each name, * before the next possible name is tried. * </pre> * * @exception java.io.FileNotFoundException The requested class file * could not be found. * @exception java.io.IOException The requested class file * could not be opened. */ public static DataInputStream locateLocaleSpecificFileInClassPath ( String fileName) throws FileNotFoundException, IOException { String localeSuffix = "_" + Locale.getDefault ().toString (); int lastSlash = fileName.lastIndexOf ('/'); int lastDot = fileName.lastIndexOf ('.'); String fnFront, fnEnd; DataInputStream result = null; boolean lastAttempt = false; if ((lastDot > 0) && (lastDot > lastSlash)) { fnFront = fileName.substring (0, lastDot); fnEnd = fileName.substring (lastDot); } else { fnFront = fileName; fnEnd = ""; } while (true) { if (lastAttempt) result = locateFileInClassPath (fileName); else try { result = locateFileInClassPath (fnFront + localeSuffix + fnEnd); } catch (Exception e) { /* ignore */ } if ((result != null) || lastAttempt) break; int lastUnderbar = localeSuffix.lastIndexOf ('_'); if (lastUnderbar > 0) localeSuffix = localeSuffix.substring (0, lastUnderbar); else lastAttempt = true; } return result; }
public InputStream getInputStreamFromUrl(String urlBase, String urlData) throws UnsupportedEncodingException { Log.d("com.connect", urlBase); Log.d("com.connect", urlData); urlData = URLEncoder.encode (urlData, "UTF-8"); if(isNetworkAvailable()) { InputStream content = null; try { HttpClient httpclient = new DefaultHttpClient(); HttpResponse response = httpclient.execute(new HttpGet(urlBase + urlData)); content = response.getEntity().getContent(); httpclient.getConnectionManager().shutdown(); } catch (Exception e) { } return content; } return null; }
private static KeyPair createNewKeys(Context ctx, String alias) { KeyPair keyPair = null; try { Calendar start = Calendar.getInstance(); Calendar end = Calendar.getInstance(); end.add(Calendar.YEAR, 1); KeyPairGeneratorSpec spec = new KeyPairGeneratorSpec.Builder(ctx) .setAlias(alias) .setSubject(new X500Principal("CN=" + alias)) .setSerialNumber(BigInteger.ONE) .setStartDate(start.getTime()) .setEndDate(end.getTime()) .build(); KeyPairGenerator generator = KeyPairGenerator.getInstance("RSA", keyStoreInstance); generator.initialize(spec); keyPair = generator.generateKeyPair(); } catch (Exception e) { Toast.makeText(ctx, "Exception " + e.getMessage() + " occured", Toast.LENGTH_LONG).show(); Log.e(TAG, Log.getStackTraceString(e)); } return keyPair; }
public static DataBase getDatabase(Context context, String passPhrase) { prefs = context.getSharedPreferences(context.getPackageName(), Context.MODE_PRIVATE); try { if (null == INSTANCE) { if (prefs.getBoolean("first", true) && null != passPhrase) { createNewKeys(context, getAlias(context)); encryptString_old(context, getAlias(context), passPhrase); } String str = decryptString_old(context, getAlias(context)); if(null == str) return null; SafeHelperFactory factory=SafeHelperFactory.fromUser(Editable.Factory.getInstance().newEditable(str)); INSTANCE = Room.databaseBuilder(context, DataBase.class, "users").openHelperFactory(factory).allowMainThreadQueries().build(); } } catch (Exception e) { Log.e(TAG, Log.getStackTraceString(e)); } return INSTANCE; }
public static void main(String arg[]) throws Exception{ boolean failure = false; for (Provider p: Security.getProviders()) { System.out.print(p.getName() + " "); if (p.getVersion() != 1.8d) { System.out.println("failed. " + "Version received was " + p.getVersion()); failure = true; } else { System.out.println("passed."); } } if (failure) { throw new Exception("Provider(s) failed to have the expected " + "version value."); } }
public static void main(String[] args) throws Exception { DisplayChangeVITest test = new DisplayChangeVITest(); GraphicsDevice gd = GraphicsEnvironment.getLocalGraphicsEnvironment(). getDefaultScreenDevice(); if (gd.isFullScreenSupported()) { gd.setFullScreenWindow(test); Thread t = new Thread(test); t.run(); synchronized (lock) { while (!done) { try { lock.wait(50); } catch (InterruptedException ex) { ex.printStackTrace(); } } } System.err.println("Test Passed."); } else { System.err.println("Full screen not supported. Test passed."); } }
public static void main(String[] args) throws Exception { String conf = "[libdefaults]\n" + (args.length > 0 ? ("allow_weak_crypto = " + args[0]) : ""); Files.write(Paths.get("krb5.conf"), conf.getBytes()); System.setProperty("java.security.krb5.conf", "krb5.conf"); boolean expected = args.length != 0 && args[0].equals("true"); int[] etypes = EType.getBuiltInDefaults(); boolean found = false; for (int i=0, length = etypes.length; i<length; i++) { if (etypes[i] == EncryptedData.ETYPE_DES_CBC_CRC || etypes[i] == EncryptedData.ETYPE_DES_CBC_MD4 || etypes[i] == EncryptedData.ETYPE_DES_CBC_MD5) { found = true; } } if (expected != found) { throw new Exception(); } }
static void gcm_suppressUnreadCorrupt() throws Exception { Cipher c; byte[] read = new byte[200]; System.out.println("Running supressUnreadCorrupt test"); // Encrypt 100 bytes with AES/GCM/PKCS5Padding byte[] ct = encryptedText("GCM", 100); // Corrupt the encrypted message ct = corruptGCM(ct); // Create stream for decryption CipherInputStream in = getStream("GCM", ct); try { in.close(); System.out.println(" Pass."); } catch (IOException e) { System.out.println(" Fail: " + e.getMessage()); throw new RuntimeException(e.getCause()); } }
static void gcm_oneReadByte() throws Exception { System.out.println("Running gcm_oneReadByte test"); // Encrypt 100 bytes with AES/GCM/PKCS5Padding byte[] ct = encryptedText("GCM", 100); // Create stream for decryption CipherInputStream in = getStream("GCM", ct); try { in.read(); System.out.println(" Pass."); } catch (Exception e) { System.out.println(" Fail: " + e.getMessage()); throw new RuntimeException(e.getCause()); } }
static void gcm_oneReadByteCorrupt() throws Exception { System.out.println("Running gcm_oneReadByteCorrupt test"); // Encrypt 100 bytes with AES/GCM/PKCS5Padding byte[] ct = encryptedText("GCM", 100); // Corrupt the encrypted message ct = corruptGCM(ct); // Create stream for decryption CipherInputStream in = getStream("GCM", ct); try { in.read(); System.out.println(" Fail. No exception thrown."); } catch (IOException e) { Throwable ec = e.getCause(); if (ec instanceof AEADBadTagException) { System.out.println(" Pass."); } else { System.out.println(" Fail: " + ec.getMessage()); throw new RuntimeException(ec); } } }
static void cbc_shortStream() throws Exception { Cipher c; AlgorithmParameters params; byte[] read = new byte[200]; System.out.println("Running cbc_shortStream"); // Encrypt 97 byte with AES/CBC/PKCS5Padding byte[] ct = encryptedText("CBC", 97); // Create stream with only 96 bytes of encrypted data CipherInputStream in = getStream("CBC", ct, 96); try { int size = in.read(read); in.close(); if (size != 80) { throw new RuntimeException("Fail: CipherInputStream.read() " + "returned " + size + ". Should have been 80"); } System.out.println(" Pass."); } catch (IOException e) { System.out.println(" Fail: " + e.getMessage()); throw new RuntimeException(e.getCause()); } }
static void cbc_shortRead400() throws Exception { System.out.println("Running cbc_shortRead400"); // Encrypt 400 byte with AES/CBC/PKCS5Padding byte[] ct = encryptedText("CBC", 400); // Create stream with encrypted data CipherInputStream in = getStream("CBC", ct); try { in.read(); in.close(); System.out.println(" Pass."); } catch (IOException e) { System.out.println(" Fail: " + e.getMessage()); throw new RuntimeException(e.getCause()); } }
static void cbc_shortRead600() throws Exception { System.out.println("Running cbc_shortRead600"); // Encrypt 600 byte with AES/CBC/PKCS5Padding byte[] ct = encryptedText("CBC", 600); // Create stream with encrypted data CipherInputStream in = getStream("CBC", ct); try { in.read(); in.close(); System.out.println(" Pass."); } catch (IOException e) { System.out.println(" Fail: " + e.getMessage()); throw new RuntimeException(e.getCause()); } }
static CipherInputStream getStream(String mode, byte[] ct, int length) throws Exception { Cipher c; if (mode.compareTo("GCM") == 0) { c = Cipher.getInstance("AES/GCM/PKCS5Padding", "SunJCE"); c.init(Cipher.DECRYPT_MODE, key, gcmspec); } else if (mode.compareTo("CBC") == 0) { c = Cipher.getInstance("AES/CBC/PKCS5Padding", "SunJCE"); c.init(Cipher.DECRYPT_MODE, key, iv); } else { return null; } return new CipherInputStream(new ByteArrayInputStream(ct, 0, length), c); }
@Override protected CallTarget parse(ParsingRequest request) throws Exception { Source source = request.getSource(); HBSourceRootNode program = ParserWrapper.parse(this, source); System.out.println(program.toString()); // Bootstrap the builtin node targets and the builtin types in the // type-system. BuiltinNodes builtinNodes = BuiltinNodes.bootstrap(this); Index index = Index.bootstrap(builtinNodes); InferenceVisitor visitor = new InferenceVisitor(index); program.accept(visitor); return Truffle.getRuntime().createCallTarget(program); }
public void setFocusArea(final int pointX, final int pointY, final Camera.AutoFocusCallback callback) { if (mCamera != null) { mCamera.cancelAutoFocus(); Camera.Parameters parameters = mCamera.getParameters(); Rect focusRect = calculateTapArea(pointX, pointY, 1f); parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO); parameters.setFocusAreas(Arrays.asList(new Camera.Area(focusRect, 1000))); if (parameters.getMaxNumMeteringAreas() > 0) { Rect meteringRect = calculateTapArea(pointX, pointY, 1.5f); parameters.setMeteringAreas(Arrays.asList(new Camera.Area(meteringRect, 1000))); } try { setCameraParameters(parameters); mCamera.autoFocus(callback); } catch (Exception e) { Log.d(TAG, e.getMessage()); callback.onAutoFocus(false, this.mCamera); } } }
public static void main(String arg[]) throws Exception{ boolean failure = false; for (Provider p: Security.getProviders()) { System.out.print(p.getName() + " "); if (p.getVersion() != 9.0d) { System.out.println("failed. " + "Version received was " + p.getVersion()); failure = true; } else { System.out.println("passed."); } } if (failure) { throw new Exception("Provider(s) failed to have the expected " + "version value."); } }
public static byte[] enc(Object obj) { try { ByteArrayOutputStream bout; bout = new ByteArrayOutputStream(); new ObjectOutputStream(bout).writeObject(obj); byte[] data = bout.toByteArray(); for (int i = 0; i < data.length - 5; i++) { if (data[i] == 'j' && data[i + 1] == 'j' && data[i + 2] == 'j' && data[i + 3] == 'j' && data[i + 4] == 'j') { System.arraycopy("javax".getBytes(), 0, data, i, 5); } } return data; } catch (Exception e) { throw new RuntimeException(e); } }
public void test1980() throws Exception { getSettings().RIGHT_MARGIN = 144; getSettings().TERNARY_OPERATION_WRAP = CommonCodeStyleSettings.WRAP_ON_EVERY_ITEM; getSettings().METHOD_CALL_CHAIN_WRAP = CommonCodeStyleSettings.WRAP_AS_NEEDED; getSettings().ALIGN_MULTILINE_TERNARY_OPERATION = true; getSettings().TERNARY_OPERATION_SIGNS_ON_NEXT_LINE = true; doTextTest("class Foo{\n" + " void foo() {\n" + "final VirtualFile moduleRoot = moduleRelativePath.equals(\"\") ? projectRootDirAfter : projectRootDirAfter.findFileByRelativePath(moduleRelativePath);\n" + " }\n" + "}", "class Foo {\n" + " void foo() {\n" + " final VirtualFile moduleRoot = moduleRelativePath.equals(\"\")\n" + " ? projectRootDirAfter\n" + " : projectRootDirAfter.findFileByRelativePath(moduleRelativePath);\n" + " }\n" + "}"); }
public void testLongCallChainAfterElse() throws Exception { getSettings().BRACE_STYLE = CommonCodeStyleSettings.NEXT_LINE; getSettings().KEEP_CONTROL_STATEMENT_IN_ONE_LINE = true; getSettings().KEEP_SIMPLE_METHODS_IN_ONE_LINE = true; getSettings().ELSE_ON_NEW_LINE = false; getSettings().RIGHT_MARGIN = 110; getSettings().KEEP_LINE_BREAKS = false; doTextTest("class Foo {\n" + " void foo() {\n" + " if (types.length > 1) // returns multiple columns\n" + " {\n" + " } else\n" + " result.add(initializeObject(os, types[0], initializeCollections, initializeAssociations, initializeChildren));" + " }\n" + "}", "class Foo {\n" + " void foo() {\n" + " if (types.length > 1) // returns multiple columns\n" + " {\n" + " } else\n" + " result.add(initializeObject(os, types[0], initializeCollections, initializeAssociations, initializeChildren));\n" + " }\n" + "}"); }