/** Connect timeout in milliseconds. Default 120 secs. */ public int connectionTimeoutMs() { long defaultNetworkTimeoutS = JavaUtils.timeStringAsSec(conf.get("spark.network.timeout", "120s")); long defaultTimeoutMs = JavaUtils.timeStringAsSec( conf.get("spark.shuffle.io.connectionTimeout", defaultNetworkTimeoutS + "s")) * 1000; return (int) defaultTimeoutMs; }
/** * Test that types with infinite recursion don't cause us to bomb out. In this case we use Enum, * as Enum<E> has E extend Enum<E>. */ public void testEnumInfiniteRecursion() { JavaUtils ju = JavaUtils.getJavaUtils(); try { Class<?> enumClass = getClass().getClassLoader().loadClass("java.lang.Enum"); ju.getTypeParams(enumClass); } catch (ClassNotFoundException cnfe) { } // ok test passed }
public void testTparReturn() throws Exception { Class<?> colClass = java.util.Collections.class; Method minMethod = colClass.getMethod("min", Collection.class); JavaUtils ju = JavaUtils.getJavaUtils(); JavaType type = JavaUtils.genTypeFromClass(minMethod.getReturnType()); assertNotNull(type.asClass()); type = ju.getReturnType(minMethod); assertEquals("T", type.toString()); }
/** * Test that we can't access a package-private member from a class which isn't a superclass, even * if a superclass is in the same package. */ public void testAccessCheck2() { TestReflective baseR = new TestReflective("Base"); TestReflective subR = new TestReflective("somepkg.Sub", baseR); TestReflective otherR = new TestReflective("Other"); assertFalse(JavaUtils.checkMemberAccess(otherR, new GenTypeClass(subR), subR, 0, false)); }
/** * Test that a subclass can only access a protected member from the superclass via an expression * of subclass type. */ public void testAccessCheck3() { TestReflective baseR = new TestReflective("Base"); TestReflective subR = new TestReflective("somepkg.Sub", baseR); TestReflective subsubR = new TestReflective("somepkg.SubSub", subR); assertFalse( JavaUtils.checkMemberAccess( baseR, new GenTypeClass(baseR), subR, Modifier.PROTECTED, false)); assertTrue( JavaUtils.checkMemberAccess( baseR, new GenTypeClass(subR), subR, Modifier.PROTECTED, false)); assertTrue( JavaUtils.checkMemberAccess( baseR, new GenTypeClass(subsubR), subR, Modifier.PROTECTED, false)); }
public DisplayPlus( final ImageCache stitchedCache, AcquisitionEngine eng, JSONObject summaryMD, boolean invX, boolean invY, boolean swapXY) { eng_ = eng; invertX_ = invX; invertY_ = invY; swapXY_ = swapXY; try { MultiStagePosition pos0 = MMStudioMainFrame.getInstance().getPositionList().getPosition(0); pos0x_ = pos0.getX(); pos0y_ = pos0.getY(); tileWidth_ = MDUtils.getHeight(summaryMD); tileHeight_ = MDUtils.getWidth(summaryMD); } catch (Exception e) { ReportingUtils.showError("Couldnt get grid info"); } vad_ = new VirtualAcquisitionDisplay(stitchedCache, eng, WINDOW_TITLE) { public void showImage(final JSONObject tags, boolean waitForDisplay) throws InterruptedException, InvocationTargetException { // Since this is multichannel camera, only show when last channel arrives try { if (MDUtils.getChannelIndex(tags) == super.getNumChannels() - 1) { super.showImage(tags, waitForDisplay); } else { ImagePlus ip = super.getHyperImage(); if (ip != null) { // canvas never gets painted so need to set painpending false ip.getCanvas().setPaintPending(false); } } } catch (JSONException ex) { } } }; DisplayControls controls = new Controls(); // Add in custom controls try { JavaUtils.setRestrictedFieldValue( vad_, VirtualAcquisitionDisplay.class, "controls_", controls); } catch (NoSuchFieldException ex) { ReportingUtils.showError("Couldn't create display controls"); } vad_.show(); // Zoom to 100% vad_.getImagePlus().getWindow().getCanvas().unzoom(); // add mouse listeners for moving grids addMouseListeners(); stitchedCache.addImageCacheListener(this); }
/** Test that method/constructor signatures are constructed correctly. */ public void testSignatures() { boolean onjava5 = true; // String majorVersion = System.getProperty("java.specification.version"); // boolean onjava6 = majorVersion.compareTo("1.6") >= 0; Method sampleMeth = null; Class<? extends JavaUtilTests> thisClass = getClass(); try { sampleMeth = thisClass.getMethod("sampleMethod", new Class[] {int.class, int.class}); } catch (NoSuchMethodException nsme) { fail(); } String sig = JavaUtils.getSignature(sampleMeth); assertEquals(sig, "void sampleMethod(int, int)"); if (onjava5) { // test a varargs method Class<?> clazz = Class.class; try { sampleMeth = clazz.getMethod("getConstructor", new Class[] {Class[].class}); } catch (NoSuchMethodException nsme) { fail(); } sig = JavaUtils.getSignature(sampleMeth); assertEquals("java.lang.reflect.Constructor getConstructor(java.lang.Class[])", sig); } try { sampleMeth = thisClass.getMethod("sampleMethod2", new Class[] {String[].class}); } catch (NoSuchMethodException nsme) { fail(); } sig = JavaUtils.getSignature(sampleMeth); assertEquals("void sampleMethod2(java.lang.String[])", sig); }
public void testRecursiveTpar() throws Exception { Class<?> colClass = java.util.Collections.class; Method minMethod = colClass.getMethod("min", Collection.class); JavaUtils ju = JavaUtils.getJavaUtils(); List<GenTypeDeclTpar> rlist = ju.getTypeParams(minMethod); assertEquals(1, rlist.size()); GenTypeDeclTpar tvar = rlist.get(0); GenTypeSolid bound = tvar.getBound(); assertEquals("java.lang.Comparable<? super T>", bound.toString()); GenTypeSolid[] ubounds = bound.getUpperBounds(); assertEquals(2, ubounds.length); // should be Object and Comparable GenTypeClass boundClass = bound.getUpperBounds()[1].asClass(); List<? extends GenTypeParameter> tpars = boundClass.getTypeParamList(); assertEquals(1, tpars.size()); GenTypeParameter tparOne = tpars.get(0); GenTypeSolid shouldBeT = tparOne.getLowerBound(); assertNotNull(shouldBeT); Set<Reflective> s = new HashSet<Reflective>(); shouldBeT.erasedSuperTypes(s); assertTrue(s.size() > 0); boolean foundComparable = false; for (Reflective r : s) { if (r.getName().equals("java.lang.Comparable")) { foundComparable = true; break; } } assertTrue(foundComparable); }
public static Connection getConnectionFromConfigFile(String filename) throws Exception { System.setProperty("http.proxyHost", "wwwcache.sanger.ac.uk"); System.setProperty("http.proxyPort", "3128"); File f = new File(filename); String s = JavaUtils.streamToString(new FileInputStream(f)); String[] lines = s.split("\n"); HashMap<String, String> props = new HashMap<String, String>(); String host = ""; String user = ""; String password = ""; String port = ""; String db = ""; for (String line : lines) { if (line.startsWith("#")) continue; String[] keyval = line.split("="); if (keyval.length < 2) continue; String k = keyval[0].trim().toLowerCase(); String v = keyval[1].trim(); if (k.equals("host")) { host = v; } else if (k.equals("user")) { user = v; } else if (k.equals("password")) { password = v; } else if (k.equals("port")) { port = v; } else if (k.equals("db")) { db = v; } } Connection c = null; Class.forName("com.mysql.jdbc.Driver").newInstance(); System.out.println( "User: "******"\n" + "Host: " + host + "\nDB: " + db + "\nPW:" + password + "\n"); if (port.equals("")) { c = DriverManager.getConnection("jdbc:mysql://" + host + "/" + db, user, password); } else { c = DriverManager.getConnection( "jdbc:mysql://" + host + ":" + port + "/" + db, user, password); } return c; }
@Override public boolean accept(File pathname) { String name = pathname.getName(); int n = name.lastIndexOf("."); String suffix = name.substring(1 + n).toLowerCase(); if (fileSuffixes_ == null || fileSuffixes_.length == 0) { return true; } if (!JavaUtils.isMac() && pathname.isDirectory()) { return true; } for (int i = 0; i < fileSuffixes_.length; ++i) { if (fileSuffixes_[i] != null && fileSuffixes_[i].toLowerCase().contentEquals(suffix)) { return true; } } return false; }
public void init() { // Make Minecraft portable ! :D final File workDirectory = Utils.getWorkingDirectory(launcherFrame); try { final List<Field> fields = JavaUtils.getFieldsWithType( classLoader.loadClass("net.minecraft.client.Minecraft"), File.class); for (final Field field : fields) { field.setAccessible(true); try { field.get(classLoader.loadClass("net.minecraft.client.Minecraft")); field.set(null, workDirectory); } catch (final IllegalArgumentException e) { } catch (final IllegalAccessException e) { } } } catch (final ClassNotFoundException e) { MCLogger.info(e.getLocalizedMessage()); } }
public static File show( Window parent, String title, File startFile, boolean selectDirectories, boolean load, final String fileDescription, final String[] fileSuffixes, boolean suggestFileName) { File selectedFile = null; GeneralFileFilter filter = new GeneralFileFilter(fileDescription, fileSuffixes); if (JavaUtils.isMac()) { if (selectDirectories) { // For Mac we only select directories, unfortunately! System.setProperty("apple.awt.fileDialogForDirectories", "true"); } int mode = load ? FileDialog.LOAD : FileDialog.SAVE; FileDialog fd; if (parent instanceof Dialog) { fd = new FileDialog((Dialog) parent, title, mode); } else if (parent instanceof Frame) { fd = new FileDialog((Frame) parent, title, mode); } else { fd = new FileDialog((Dialog) null, title, mode); } if (startFile != null) { if (startFile.isDirectory()) { fd.setDirectory(startFile.getAbsolutePath()); } else { fd.setDirectory(startFile.getParent()); } if (!load && suggestFileName) { fd.setFile(startFile.getName()); } } if (fileSuffixes != null) { fd.setFilenameFilter(filter); } fd.setVisible(true); if (selectDirectories) { System.setProperty("apple.awt.fileDialogForDirectories", "false"); } if (fd.getFile() != null) { selectedFile = new File(fd.getDirectory() + "/" + fd.getFile()); if (mode == FileDialog.SAVE) { if (!filter.accept(selectedFile)) { selectedFile = new File(selectedFile.getAbsolutePath() + "." + fileSuffixes[0]); } } } fd.dispose(); } else { JFileChooser fc = new JFileChooser(); if (startFile != null) { if ((!load && suggestFileName) || startFile.isDirectory()) { fc.setSelectedFile(startFile); } else { fc.setSelectedFile(startFile.getParentFile()); } } fc.setDialogTitle(title); if (selectDirectories) { fc.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); } if (fileSuffixes != null) { fc.setFileFilter(filter); } int returnVal; if (load) { returnVal = fc.showOpenDialog(parent); } else { returnVal = fc.showSaveDialog(parent); } if (returnVal == JFileChooser.APPROVE_OPTION) { selectedFile = fc.getSelectedFile(); } } return selectedFile; }
/** Timeout for a single round trip of SASL token exchange, in milliseconds. */ public int saslRTTimeoutMs() { return (int) JavaUtils.timeStringAsSec(conf.get("spark.shuffle.sasl.timeout", "30s")) * 1000; }
/** Maximum number of bytes to be encrypted at a time when SASL encryption is enabled. */ public int maxSaslEncryptedBlockSize() { return Ints.checkedCast( JavaUtils.byteStringAsBytes(conf.get("spark.network.sasl.maxEncryptedBlockSize", "64k"))); }
/** * Time (in milliseconds) that we will wait in order to perform a retry after an IOException. Only * relevant if maxIORetries > 0. */ public int ioRetryWaitTimeMs() { return (int) JavaUtils.timeStringAsSec(conf.get("spark.shuffle.io.retryWait", "5s")) * 1000; }