Example usage for java.net URL getFile

List of usage examples for java.net URL getFile

Introduction

In this page you can find the example usage for java.net URL getFile.

Prototype

public String getFile() 

Source Link

Document

Gets the file name of this URL .

Usage

From source file:org.owasp.webgoat.lessons.admin.MenuToLessonMapperScreen.java

/**
 * Description of the Method//from ww w. j a  va 2s .  c  om
 *
 * @param s
 *            Description of the Parameter
 * @return Description of the Return Value
 */
public Element makeMenuToLessonMapping(WebSession s) {
    ElementContainer ec = new ElementContainer();
    Table t = new Table().setCellSpacing(0).setCellPadding(2).setBorder(1);
    t.addElement(makeHeaderRow());

    for (AbstractLesson lesson : s.getCourse().getLessons(s, AbstractLesson.USER_ROLE)) {
        TR tr = new TR();
        tr.addElement(new TD().addElement(lesson.getName()));

        URL jarLocation = lesson.getClass().getProtectionDomain().getCodeSource().getLocation();
        String projectName = removeVersion(stripFilenameExtension(getFilename(jarLocation.getFile())));
        tr.addElement(new TD().addElement(projectName));

        tr.addElement(new TD().addElement(lesson.getClass().getName() + ".java"));
        t.addElement(tr);
    }
    ec.addElement(t);
    return (ec);
}

From source file:gobblin.data.management.copy.converter.DecryptConverterTest.java

@Test
public void testConvertGpgRecord() throws Exception {
    final String expectedFileContents = "123456789";
    final String passphrase = "12";
    DecryptConverter converter = new DecryptConverter();
    WorkUnitState workUnitState = new WorkUnitState();

    try {/*from   w  w w .  j a v  a2 s.  co m*/
        setEncryptedPassphrase(passphrase, workUnitState);
        converter.init(workUnitState);

        FileSystem fs = FileSystem.getLocal(new Configuration());

        URL url = getClass().getClassLoader().getResource("decryptConverterTest/decrypt-test.txt.gpg");
        Assert.assertNotNull(url);

        String gpgFilePath = url.getFile();
        try (FSDataInputStream gpgFileInput = fs.open(new Path(gpgFilePath))) {
            FileAwareInputStream fileAwareInputStream = new FileAwareInputStream(
                    CopyableFileUtils.getTestCopyableFile(), gpgFileInput);

            Iterable<FileAwareInputStream> iterable = converter.convertRecord("outputSchema",
                    fileAwareInputStream, workUnitState);
            fileAwareInputStream = Iterables.getFirst(iterable, null);
            Assert.assertNotNull(fileAwareInputStream);

            String actual = IOUtils.toString(fileAwareInputStream.getInputStream(), Charsets.UTF_8);
            Assert.assertEquals(actual, expectedFileContents);
        }
    } finally {
        deleteMasterPwdFile();
        converter.close();
    }
}

From source file:org.apache.cxf.fediz.service.idp.STSPortFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    Assert.isTrue(applicationContext != null, "Application context must not be null");
    STSAuthenticationProvider authProvider = authenticationProvider;
    if (authProvider == null) {
        authProvider = applicationContext.getBean(STSAuthenticationProvider.class);
    }//from  w  w w . ja va 2s . com
    Assert.isTrue(authProvider != null, "STSAuthenticationProvider must be configured");

    //Only update the port if HTTPS is used, otherwise ignored (like retrieving the WADL over HTTP)
    if (!isPortSet && request.isSecure()) {
        try {
            URL url = new URL(authProvider.getWsdlLocation());
            if (url.getPort() == 0) {
                URL updatedUrl = new URL(url.getProtocol(), url.getHost(), request.getLocalPort(),
                        url.getFile());
                setSTSWsdlUrl(authProvider, updatedUrl.toString());
                LOG.info("STSAuthenticationProvider.wsdlLocation set to " + updatedUrl.toString());
            } else {
                setSTSWsdlUrl(authProvider, url.toString());
            }
        } catch (MalformedURLException e) {
            LOG.error("Invalid Url '" + authProvider.getWsdlLocation() + "': " + e.getMessage());
        }
    }

    chain.doFilter(request, response);
}

From source file:com.linkedin.pinot.query.selection.SelectionQueriesSVTest.java

@BeforeClass
public void setup() throws Exception {
    FileUtils.deleteQuietly(INDEX_DIR);/*from  w  ww  . j  a v  a 2  s .c  o  m*/

    // Get resource file path.
    URL resource = getClass().getClassLoader().getResource(AVRO_DATA);
    Assert.assertNotNull(resource);
    String filePath = resource.getFile();

    // Build the index segment.
    SegmentGeneratorConfig config = SegmentTestUtils.getSegmentGenSpecWithSchemAndProjectedColumns(
            new File(filePath), INDEX_DIR, "time_day", TimeUnit.DAYS, "testTable");
    SegmentIndexCreationDriver driver = new SegmentIndexCreationDriverImpl();
    driver.init(config);
    driver.build();

    // Load the index segment.
    File indexSegmentDir = new File(INDEX_DIR, driver.getSegmentName());
    _indexSegment = ColumnarSegmentLoader.load(indexSegmentDir, ReadMode.heap);

    // Initialize the data source map.
    _dataSourceMap = new HashMap<>();
    _dataSourceMap.put("column11", _indexSegment.getDataSource("column11"));
    _dataSourceMap.put("column12", _indexSegment.getDataSource("column12"));
    _dataSourceMap.put("column13", _indexSegment.getDataSource("column13"));
    _dataSourceMap.put("met_impressionCount", _indexSegment.getDataSource("met_impressionCount"));

    // Build the selection ONLY query.
    _selectionOnlyQuery = new Selection();
    _selectionOnlyQuery.setSelectionColumns(Arrays.asList("column12", "column11", "met_impressionCount"));
    _selectionOnlyQuery.setSize(10);

    // Build the selection ORDER BY query.
    _selectionOrderByQuery = new Selection();
    _selectionOrderByQuery.setSelectionColumns(Arrays.asList("column12", "column11", "met_impressionCount"));
    _selectionOrderByQuery.setSize(10);
    SelectionSort selectionSort1 = new SelectionSort();
    selectionSort1.setColumn("column13");
    SelectionSort selectionSort2 = new SelectionSort();
    selectionSort2.setColumn("column11");
    _selectionOrderByQuery.setSelectionSortSequence(Arrays.asList(selectionSort1, selectionSort2));
}

From source file:ch.entwine.weblounge.common.impl.site.I18nDictionaryImpl.java

/**
 * Adds the the dictionary found in <code>file</code> to the current i18n
 * definitions. The implementation tries to derive the language from the
 * filename, which is expected to be of the form
 * <code>&lt;name&gt;_&lt;language&gt;.xml</code>, where &lt;language&gt; is
 * the ISO language identifier./*ww  w .  j  av a  2s.  com*/
 * 
 * @param url
 *          the i18n dictionary
 */
public void addDictionary(URL url) {
    String name = FilenameUtils.getBaseName(url.getFile());
    Language language = null;
    String languageId = null;
    int lidstart = name.indexOf('_') + 1;
    if (lidstart > 0 && lidstart < name.length()) {
        languageId = name.substring(lidstart);
        language = LanguageUtils.getLanguage(languageId);
    }
    addDictionary(url, language);
}

From source file:hrpod.tools.nlp.NLPTools.java

public void setPosModel() {
    try {//w w w . j  a va 2  s  .  c o m
        URL url = this.getClass().getResource(modelBasePath + "en-pos-maxent.bin");
        this.posModel = new POSModel(new FileInputStream(new File(url.getFile())));
    } catch (Exception e) {
        logger.error("Error is setPosModel", e);
    }
}

From source file:org.ohmage.query.impl.ImageQueries.java

public void deleteImageDiskOnly(URL imageUrl) {
    try {//from w w  w. j  a  v  a  2s  .  com
        // Delete the original image.
        if ((new File(imageUrl.getFile())).delete()) {
            LOGGER.warn("The image no longer existed.");
        }

        // Delete the scaled image.
        if ((new File((new URL(imageUrl + IMAGE_SCALED_EXTENSION)).getFile())).delete()) {
            LOGGER.warn("The scaled image no longer existed.");
        }
    } catch (MalformedURLException e) {
        LOGGER.warn("The URL was malformed, but we are deleting the image anyway.", e);
    } catch (SecurityException e) {
        LOGGER.error("The system would not allow us to delete the image.", e);
    }
}

From source file:at.tuwien.minimee.migration.engines.MonitorEngineWinPslist.java

/**
 * Copies resource file 'from' from destination 'to' and set execution permission.
 * /* w w  w  .  j ava 2 s.  co m*/
 * @param from
 * @param to
 * @throws Exception
 */
protected void copyFile(String from, String to, String workingDirectory) throws Exception {

    //
    // copy the shell script to the working directory
    //
    URL monitorCallShellScriptUrl = Thread.currentThread().getContextClassLoader().getResource(from);
    File f = new File(monitorCallShellScriptUrl.getFile());
    String directoryPath = f.getAbsolutePath();

    /*
    URL urlJar = new URL(directoryPath.substring(
            directoryPath.indexOf("file:"),
            directoryPath.indexOf("plato.jar")+"plato.jar".length()));
            
            
    JarFile jf = new JarFile(urlJar.getFile());
            
    JarEntry je = jf.getJarEntry(from);
            
    String fileName = je.getName();
    */
    InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(from);

    File outScriptFile = new File(to);

    FileOutputStream fos = new FileOutputStream(outScriptFile);
    int nextChar;
    while ((nextChar = in.read()) != -1) {
        fos.write(nextChar);
    }
    fos.flush();
    fos.close();
}

From source file:com.linkedin.pinot.query.selection.SelectionQueriesMVTest.java

@BeforeClass
public void setup() throws Exception {
    FileUtils.deleteQuietly(INDEX_DIR);/*w w  w.  j a v  a2  s.c  om*/

    // Get resource file path.
    URL resource = getClass().getClassLoader().getResource(AVRO_DATA);
    Assert.assertNotNull(resource);
    String filePath = resource.getFile();

    // Build the index segment.
    SegmentGeneratorConfig config = SegmentTestUtils.getSegmentGenSpecWithSchemAndProjectedColumns(
            new File(filePath), INDEX_DIR, "daysSinceEpoch", TimeUnit.DAYS, "testTable");
    SegmentIndexCreationDriver driver = new SegmentIndexCreationDriverImpl();
    driver.init(config);
    driver.build();

    // Load the index segment.
    File indexSegmentDir = new File(INDEX_DIR, driver.getSegmentName());
    _indexSegment = ColumnarSegmentLoader.load(indexSegmentDir, ReadMode.heap);

    // Initialize the data source map.
    _dataSourceMap = new HashMap<>();
    _dataSourceMap.put("column1", _indexSegment.getDataSource("column1"));
    _dataSourceMap.put("column2", _indexSegment.getDataSource("column2"));
    _dataSourceMap.put("column6", _indexSegment.getDataSource("column6"));
    _dataSourceMap.put("count", _indexSegment.getDataSource("count"));

    // Build the selection ONLY query.
    _selectionOnlyQuery = new Selection();
    _selectionOnlyQuery.setSelectionColumns(Arrays.asList("column6", "column1", "count"));
    _selectionOnlyQuery.setSize(10);

    // Build the selection ORDER BY query.
    _selectionOrderByQuery = new Selection();
    _selectionOrderByQuery.setSelectionColumns(Arrays.asList("column6", "column1", "count"));
    _selectionOrderByQuery.setSize(10);
    SelectionSort selectionSort1 = new SelectionSort();
    selectionSort1.setColumn("column2");
    SelectionSort selectionSort2 = new SelectionSort();
    selectionSort2.setColumn("column1");
    _selectionOrderByQuery.setSelectionSortSequence(Arrays.asList(selectionSort1, selectionSort2));
}

From source file:hrpod.tools.nlp.NLPTools.java

public void setTokenModel() {
    try {/*from  ww  w  .j a  va 2 s.c  om*/
        URL tmUrl = this.getClass().getResource(modelBasePath + "en-token.bin");
        this.tokenModel = new TokenizerModel(new FileInputStream(new File(tmUrl.getFile())));
    } catch (Exception e) {
        logger.error("Error is setTokenModel", e);
    }
}