List of usage examples for java.net URL getFile
public String getFile()
From source file:com.linkedin.pinot.queries.BaseSingleValueQueriesTest.java
@BeforeTest public void buildSegment() throws Exception { FileUtils.deleteQuietly(INDEX_DIR);/*from w w w . j ava 2 s . c om*/ // Get resource file path. URL resource = getClass().getClassLoader().getResource(AVRO_DATA); Assert.assertNotNull(resource); String filePath = resource.getFile(); // Build the segment schema. Schema schema = new Schema.SchemaBuilder().setSchemaName("testTable") .addMetric("column1", FieldSpec.DataType.INT).addMetric("column3", FieldSpec.DataType.INT) .addSingleValueDimension("column5", FieldSpec.DataType.STRING) .addSingleValueDimension("column6", FieldSpec.DataType.INT) .addSingleValueDimension("column7", FieldSpec.DataType.INT) .addSingleValueDimension("column9", FieldSpec.DataType.INT) .addSingleValueDimension("column11", FieldSpec.DataType.STRING) .addSingleValueDimension("column12", FieldSpec.DataType.STRING) .addMetric("column17", FieldSpec.DataType.INT).addMetric("column18", FieldSpec.DataType.INT) .addTime("daysSinceEpoch", TimeUnit.DAYS, FieldSpec.DataType.INT).build(); // Create the segment generator config. SegmentGeneratorConfig segmentGeneratorConfig = new SegmentGeneratorConfig(schema); segmentGeneratorConfig.setInputFilePath(filePath); segmentGeneratorConfig.setTableName("testTable"); segmentGeneratorConfig.setOutDir(INDEX_DIR.getAbsolutePath()); segmentGeneratorConfig.setInvertedIndexCreationColumns( Arrays.asList("column6", "column7", "column11", "column17", "column18")); // Build the index segment. SegmentIndexCreationDriver driver = new SegmentIndexCreationDriverImpl(); driver.init(segmentGeneratorConfig); driver.build(); }
From source file:com.cedarsoftware.ncube.NCubeManager.java
/** * Still used in getNCubesFromResource/*from w w w. j a v a 2 s. co m*/ */ private static JsonObject getJsonObjectFromResource(String name) throws IOException { JsonReader reader = null; try { URL url = NCubeManager.class.getResource("/" + name); File jsonFile = new File(url.getFile()); InputStream in = new BufferedInputStream(new FileInputStream(jsonFile)); reader = new JsonReader(in, true); return (JsonObject) reader.readObject(); } finally { IOUtilities.close(reader); } }
From source file:com.aliyun.openservices.odps.console.commands.HtmlModeCommand.java
public void run() throws OdpsException, ODPSConsoleException { getContext().setHtmlMode(true);/* ww w .ja v a 2s. c o m*/ URL url = this.getClass().getClassLoader().getResource("html"); if (url == null) { throw new ODPSConsoleException("Html folder not exists in classpath."); } File source = new File(url.getFile()); File dest = new File("html"); if (dest.exists()) { System.err.println(dest + "exists."); return; } try { FileUtils.copyDirectory(source, dest); } catch (IOException e) { throw new ODPSConsoleException(e.getMessage(), e); } }
From source file:es.molabs.io.utils.test.FileWatcherRunnableTest.java
@Test public void testEntryCreate() throws Throwable { URL file = getClass().getResource("/es/molabs/io/utils/test/filewatcher/"); // Deletes the file if already exists File newFile = new File(file.getFile() + File.separator + "test-create.txt"); if (newFile.exists()) newFile.delete();/*from w w w .jav a 2 s . c o m*/ WatchService watchService = FileSystems.getDefault().newWatchService(); FileWatcherHandler handler = Mockito.mock(FileWatcherHandler.class); FileWatcherRunnable fileWatcherRunnable = new FileWatcherRunnable(watchService, handler); fileWatcherRunnable.addFile(file); executor.submit(fileWatcherRunnable); // Creates the file newFile.createNewFile(); // Waits the refresh time Thread.sleep(fileWatcherRunnable.getRefreshTime() + REFRESH_MARGIN); // Checks that the event handler has been called one time Mockito.verify(handler, Mockito.times(1)).entryCreate(Mockito.any()); // Stops the service watchService.close(); }
From source file:com.linkedin.pinot.routing.RandomRoutingTableTest.java
@Test public void testHelixExternalViewBasedRoutingTable() throws Exception { URL resourceUrl = getClass().getClassLoader().getResource("SampleExternalView.json"); Assert.assertNotNull(resourceUrl);//from w ww .j a v a2s. com String fileName = resourceUrl.getFile(); String tableName = "testTable_OFFLINE"; InputStream evInputStream = new FileInputStream(fileName); ZNRecordSerializer znRecordSerializer = new ZNRecordSerializer(); ZNRecord externalViewRecord = (ZNRecord) znRecordSerializer.deserialize(IOUtils.toByteArray(evInputStream)); int totalRuns = 10000; RoutingTableBuilder routingStrategy = new BalancedRandomRoutingTableBuilder(10); HelixExternalViewBasedRouting routingTable = new HelixExternalViewBasedRouting(null, new PercentageBasedRoutingTableSelector(), null, new BaseConfiguration()); routingTable.setSmallClusterRoutingTableBuilder(routingStrategy); ExternalView externalView = new ExternalView(externalViewRecord); routingTable.markDataResourceOnline(tableName, externalView, getInstanceConfigs(externalView)); double[] globalArrays = new double[9]; for (int numRun = 0; numRun < totalRuns; ++numRun) { RoutingTableLookupRequest request = new RoutingTableLookupRequest(tableName, Collections.<String>emptyList()); Map<ServerInstance, SegmentIdSet> serversMap = routingTable.findServers(request); TreeSet<ServerInstance> serverInstances = new TreeSet<ServerInstance>(serversMap.keySet()); int i = 0; double[] arrays = new double[9]; for (ServerInstance serverInstance : serverInstances) { globalArrays[i] += serversMap.get(serverInstance).getSegments().size(); arrays[i++] = serversMap.get(serverInstance).getSegments().size(); } for (int j = 0; i < arrays.length; ++j) { Assert.assertTrue(arrays[j] / totalRuns <= 31); Assert.assertTrue(arrays[j] / totalRuns >= 28); } // System.out.println(Arrays.toString(arrays) + " : " + new StandardDeviation().evaluate(arrays) + " : " + new Mean().evaluate(arrays)); } for (int i = 0; i < globalArrays.length; ++i) { Assert.assertTrue(globalArrays[i] / totalRuns <= 31); Assert.assertTrue(globalArrays[i] / totalRuns >= 28); } // System.out.println(Arrays.toString(globalArrays) + " : " + new StandardDeviation().evaluate(globalArrays) + " : " // + new Mean().evaluate(globalArrays)); }
From source file:com.linkedin.pinot.server.api.resources.BaseResourceTest.java
@BeforeClass public void setUp() throws Exception { FileUtils.deleteQuietly(INDEX_DIR);/*from ww w . j av a 2 s .c o m*/ Assert.assertTrue(INDEX_DIR.mkdirs()); URL resourceUrl = getClass().getClassLoader().getResource(AVRO_DATA_PATH); Assert.assertNotNull(resourceUrl); _avroFile = new File(resourceUrl.getFile()); // Mock the instance data manager InstanceDataManager instanceDataManager = mock(InstanceDataManager.class); when(instanceDataManager.getTableDataManager(anyString())).thenAnswer(new Answer<TableDataManager>() { @SuppressWarnings("SuspiciousMethodCalls") @Override public TableDataManager answer(InvocationOnMock invocation) throws Throwable { return _tableDataManagerMap.get(invocation.getArguments()[0]); } }); when(instanceDataManager.getTableDataManagers()).thenReturn(_tableDataManagerMap.values()); // Mock the server instance ServerInstance serverInstance = mock(ServerInstance.class); when(serverInstance.getInstanceDataManager()).thenReturn(instanceDataManager); // Add the default table and segment addTable(TABLE_NAME); setUpSegment("default"); _adminApiApplication = new AdminApiApplication(serverInstance); _adminApiApplication.start(CommonConstants.Server.DEFAULT_ADMIN_API_PORT); _webTarget = ClientBuilder.newClient().target(_adminApiApplication.getBaseUri()); }
From source file:com.photon.maven.plugins.android.AbstractAndroidMojoTest.java
public void givenApidemosApkThenPackageIsFound() throws IOException, MojoExecutionException { final URL resource = this.getClass().getResource("apidemos-0.1.0-SNAPSHOT.apk"); final String foundPackage = androidMojo.extractPackageNameFromApk(new File(resource.getFile())); Assert.assertEquals("com.example.android.apis", foundPackage); }
From source file:dk.statsbiblioteket.alto.AnagramHashingTest.java
private File getInputFolder() { for (File input : INPUT_FOLDERS) { // Directly available? if (input.exists()) { return input; }//w w w. j ava 2 s. c o m // Maybe on the class path? URL url = Thread.currentThread().getContextClassLoader().getResource(input.toString()); if (url != null) { return new File(url.getFile()); } log.debug("Sample '" + input.getAbsolutePath() + "' did not exist"); } throw new IllegalArgumentException("None of the possible input folders existed. " + "Please provide at least one folder containing .alto.xml-files"); }
From source file:es.molabs.io.utils.test.FileWatcherRunnableTest.java
@Test public void testEntryDelete() throws Throwable { URL file = getClass().getResource("/es/molabs/io/utils/test/filewatcher/"); // Creates the file if it does not exist File newFile = new File(file.getFile() + File.separator + "test-delete.txt"); if (!newFile.exists()) newFile.createNewFile();//from w w w. j a va 2 s.com WatchService watchService = FileSystems.getDefault().newWatchService(); FileWatcherHandler handler = Mockito.mock(FileWatcherHandler.class); FileWatcherRunnable fileWatcherRunnable = new FileWatcherRunnable(watchService, handler); fileWatcherRunnable.addFile(file); executor.submit(fileWatcherRunnable); // Delete the file newFile.delete(); // Waits the refresh time Thread.sleep(fileWatcherRunnable.getRefreshTime() + REFRESH_MARGIN); // Checks that the event handler has been called one time Mockito.verify(handler, Mockito.times(1)).entryDelete(Mockito.any()); // Stops the service watchService.close(); }
From source file:de.klemp.middleware.controller.Controller.java
/** * !!!! Important Method for creating new classes !!!! This method returns * the different classes of the first and second component. If a new class * is created, then it has to be added into this method. This method is * needed for the GUI. Method which use this method: getClassNames(...), * searchMethods(), getMethod()//www . j a v a2 s . com * * @param component * 1 or 2 * @return ArrayList: list with objects of the classes */ private static ArrayList<Object> getClasses(String component) { // http://tutorials.jenkov.com/java-reflection/dynamic-class-loading-reloading.html // http://stackoverflow.com/questions/1456930/how-do-i-read-all-classes-from-a-java-package-in-the-classpath // http://www.dzone.com/snippets/get-all-classes-within-package ArrayList<Object> classes = new ArrayList<Object>(); Enumeration<URL> urls; try { ClassLoader loader = Thread.currentThread().getContextClassLoader(); urls = loader.getResources(component); while (urls.hasMoreElements()) { URL url = urls.nextElement(); File file = new File(url.getFile()); File[] files = file.listFiles(); for (int i = 0; i < files.length; i++) { String[] f = files[i].getName().split("\\."); Class c; try { c = loader.loadClass(component + "." + f[0]); classes.add(c.newInstance()); } catch (ClassNotFoundException | InstantiationException | IllegalAccessException e) { logger.error("Classes could not be refreshed", e); } } } } catch (IOException e) { logger.error("SQL Exception", e); } return classes; }