Example usage for java.nio.file Path toString

List of usage examples for java.nio.file Path toString

Introduction

In this page you can find the example usage for java.nio.file Path toString.

Prototype

String toString();

Source Link

Document

Returns the string representation of this path.

Usage

From source file:it.greenvulcano.configuration.BaseConfigurationManager.java

@Override
public byte[] export(String name) throws IOException, FileNotFoundException {

    Path configurationPath = getConfigurationPath(name);

    if (Files.exists(configurationPath) && !Files.isDirectory(configurationPath)) {
        return Files.readAllBytes(configurationPath);
    } else {//w w w  .  j av a 2s.  c  o  m
        throw new FileNotFoundException(configurationPath.toString());
    }
}

From source file:company.gonapps.loghut.dao.PostDao.java

public List<String> getYears() throws IOException {
    List<String> years = new LinkedList<>();

    rrwl.readLock().lock();/*from   ww  w  . j av  a 2  s. co m*/
    try (DirectoryStream<Path> ds = Files
            .newDirectoryStream(Paths.get(settingDao.getSetting("posts.directory")))) {
        for (Path path : ds) {
            Matcher matcher = postYearPattern.matcher(path.toString());
            if (matcher.find() && Files.isDirectory(path))
                years.add(matcher.group(1));
        }
    } finally {
        rrwl.readLock().unlock();
    }

    Collections.sort(years, new YearComparator());
    return years;
}

From source file:io.github.dsheirer.gui.SDRTrunk.java

public SDRTrunk() {
    mLog.info("*******************************************************************");
    mLog.info("**** sdrtrunk: a trunked radio and digital decoding application ***");
    mLog.info("****  website: https://github.com/dsheirer/sdrtrunk             ***");
    mLog.info("*******************************************************************");
    mLog.info("Memory Logging Format: [Used/Allocated PercentUsed%]");
    mLog.info("Host CPU Cores:        " + Runtime.getRuntime().availableProcessors());
    mLog.info("Host OS Name:          " + System.getProperty("os.name"));
    mLog.info("Host OS Arch:          " + System.getProperty("os.arch"));
    mLog.info("Host OS Version:       " + System.getProperty("os.version"));
    mLog.info("Host Max Java Memory:  " + FileUtils.byteCountToDisplaySize(Runtime.getRuntime().maxMemory()));

    //Setup the application home directory
    Path home = getHomePath();

    ThreadPool.logSettings();//from  w ww . j  a  va  2 s  . c  om

    mLog.info("Home path: " + home.toString());

    //Load properties file
    if (home != null) {
        loadProperties(home);
    }

    //Log current properties setting
    SystemProperties.getInstance().logCurrentSettings();

    TunerConfigurationModel tunerConfigurationModel = new TunerConfigurationModel();
    TunerModel tunerModel = new TunerModel(tunerConfigurationModel);

    mIconManager = new IconManager();

    mSettingsManager = new SettingsManager(tunerConfigurationModel);

    AliasModel aliasModel = new AliasModel();

    ChannelModel channelModel = new ChannelModel();

    ChannelMapModel channelMapModel = new ChannelMapModel();

    EventLogManager eventLogManager = new EventLogManager();

    RecorderManager recorderManager = new RecorderManager();

    SourceManager sourceManager = new SourceManager(tunerModel, mSettingsManager);

    ChannelProcessingManager channelProcessingManager = new ChannelProcessingManager(channelModel,
            channelMapModel, aliasModel, eventLogManager, recorderManager, sourceManager);
    channelProcessingManager.addAudioPacketListener(recorderManager);

    channelModel.addListener(channelProcessingManager);

    ChannelSelectionManager channelSelectionManager = new ChannelSelectionManager(channelModel);
    channelModel.addListener(channelSelectionManager);

    AliasActionManager aliasActionManager = new AliasActionManager();
    channelProcessingManager.addMessageListener(aliasActionManager);

    AudioManager audioManager = new AudioManager(sourceManager.getMixerManager());
    channelProcessingManager.addAudioPacketListener(audioManager);

    mBroadcastModel = new BroadcastModel(mIconManager);

    channelProcessingManager.addAudioPacketListener(mBroadcastModel);

    MapService mapService = new MapService(mIconManager);
    channelProcessingManager.addMessageListener(mapService);

    mControllerPanel = new ControllerPanel(audioManager, aliasModel, mBroadcastModel, channelModel,
            channelMapModel, channelProcessingManager, mIconManager, mapService, mSettingsManager,
            sourceManager, tunerModel);

    mSpectralPanel = new SpectralDisplayPanel(channelModel, channelProcessingManager, mSettingsManager);

    TunerSpectralDisplayManager tunerSpectralDisplayManager = new TunerSpectralDisplayManager(mSpectralPanel,
            channelModel, channelProcessingManager, mSettingsManager);
    tunerModel.addListener(tunerSpectralDisplayManager);
    tunerModel.addListener(this);

    PlaylistManager playlistManager = new PlaylistManager(aliasModel, mBroadcastModel, channelModel,
            channelMapModel);

    playlistManager.init();

    mLog.info("starting main application gui");

    //Initialize the GUI
    initGUI();

    tunerModel.requestFirstTunerDisplay();

    //Start the gui
    EventQueue.invokeLater(new Runnable() {
        public void run() {
            try {
                mMainGui.setVisible(true);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
}

From source file:company.gonapps.loghut.dao.PostDao.java

public List<String> getMonths(int year) throws IOException {
    List<String> months = new LinkedList<>();

    rrwl.readLock().lock();//w w w. j  a v  a2 s  .  co m
    try (DirectoryStream<Path> ds = Files.newDirectoryStream(
            Paths.get(settingDao.getSetting("posts.directory") + "/" + String.format("%04d", year)))) {

        for (Path path : ds) {
            Matcher matcher = postMonthPattern.matcher(path.toString());
            if (matcher.find() && Files.isDirectory(path))
                months.add(matcher.group(1));
        }
    }
    rrwl.readLock().unlock();

    Collections.sort(months, new MonthComparator());

    return months;
}

From source file:cn.tst.sbjxzzglxt.MoKuai.SheBeiGuanLi.WenDangJiTuPianGuanLi.WenDangJiTuPianGuanLiBizLogicImpl.java

private void uploadFile(ViewModel vm) {
    String fileUploadPath = Controller.FILE_UPLOAD_PATH;
    UploadedFile file = vm.getCurrentUploadedFile();
    final String EXTENSION_NAME = FilenameUtils.getExtension(file.getFileName());
    final String FILE_NAME_ON_SERVER = UUID.randomUUID().toString().concat(CConst.DOT).concat(EXTENSION_NAME);
    try {/*from  ww  w .j  a va 2 s .  c o  m*/
        Path originFilePath = Paths.get(fileUploadPath, SepC.UploadFileType.ORIGIN, FILE_NAME_ON_SERVER);
        Path compressedFilePath = Paths.get(fileUploadPath, SepC.UploadFileType.COMPRESSION,
                FILE_NAME_ON_SERVER);
        Path previewFilePath = Paths.get(fileUploadPath, SepC.UploadFileType.PREVIEW, FILE_NAME_ON_SERVER);

        Thumbnails.of(file.getInputstream()).scale(1, 1).toFile(new File(originFilePath.toString()));
        Thumbnails.of(file.getInputstream()).size(400, 320).toFile(new File(compressedFilePath.toString()));
        Thumbnails.of(file.getInputstream()).size(85, 100).toFile(new File(previewFilePath.toString()));
    } catch (IOException ex) {

    }
    vm.getEquipmentDocumentInEdit().setFOriginalName(file.getFileName());
    vm.getEquipmentDocumentInEdit().setFNameOnServer(FILE_NAME_ON_SERVER);
    //        List<LTEquipGraphic> list = equipmentGraphicFacade.findByOriginalName(file.getFileName());
    //        vm.getEquipmentDocumentInEdit().setFVer(list.toArray().length + 1);
}

From source file:com.google.cloud.dataflow.sdk.io.TextIOTest.java

License:asdf

public static <T> void assertOutputFiles(T[] elems, final String header, final String footer, Coder<T> coder,
        int numShards, Path rootLocation, String outputName, String shardNameTemplate) throws Exception {
    List<File> expectedFiles = new ArrayList<>();
    if (numShards == 0) {
        String pattern = resolve(rootLocation.toAbsolutePath().toString(), outputName + "*");
        for (String expected : IOChannelUtils.getFactory(pattern).match(pattern)) {
            expectedFiles.add(new File(expected));
        }/*from   ww  w . j av a2  s . c  o  m*/
    } else {
        for (int i = 0; i < numShards; i++) {
            expectedFiles.add(new File(rootLocation.toString(),
                    IOChannelUtils.constructName(outputName, shardNameTemplate, "", i, numShards)));
        }
    }

    List<List<String>> actual = new ArrayList<>();
    for (File tmpFile : expectedFiles) {
        try (BufferedReader reader = new BufferedReader(new FileReader(tmpFile))) {
            List<String> currentFile = new ArrayList<>();
            for (;;) {
                String line = reader.readLine();
                if (line == null) {
                    break;
                }
                currentFile.add(line);
            }
            actual.add(currentFile);
        }
    }

    List<String> expectedElements = new ArrayList<>(elems.length);
    for (T elem : elems) {
        byte[] encodedElem = CoderUtils.encodeToByteArray(coder, elem);
        String line = new String(encodedElem);
        expectedElements.add(line);
    }

    List<String> actualElements = Lists.newArrayList(Iterables
            .concat(FluentIterable.from(actual).transform(removeHeaderAndFooter(header, footer)).toList()));

    assertThat(actualElements, containsInAnyOrder(expectedElements.toArray()));

    assertTrue(Iterables.all(actual, haveProperHeaderAndFooter(header, footer)));
}

From source file:br.com.thiaguten.archive.ZipArchive.java

/**
 * Override to make use of the ZipArchive#createArchiveOutputStream(Path path) method
 * instead of the method ZipArchive#createArchiveOutputStream(BufferedOutputStream bufferedOutputStream).
 *//*ww  w.  j  a  v a2s  .c  o  m*/
@Override
public Path compress(Path... paths) throws IOException {
    Path compress = null;
    ArchiveOutputStream archiveOutputStream = null;

    for (Path path : paths) {
        // get path infos
        final Path parent = path.getParent();
        final String name = path.getFileName().toString();
        final boolean isDirectory = isDirectory(path);

        if (compress == null) {
            // create compress file
            String compressName = (paths.length == 1 ? name : getName());
            compress = Paths.get(parent.toString(), compressName + getExtension());

            // creates a new compress file to not override if already exists
            // if you do not want this behavior, just comment this line
            compress = createFile(ArchiveAction.COMPRESS, parent, compress);

            // open compress file stream
            archiveOutputStream = createArchiveOutputStream(compress);

            logger.debug("creating the archive file " + compressName);
        }

        logger.debug("reading path " + path);

        if (isDirectory) {
            compressDirectory(parent, path, archiveOutputStream);
        } else {
            compressFile(parent, path, archiveOutputStream);
        }
    }

    // closing streams
    if (archiveOutputStream != null) {
        archiveOutputStream.finish();
        archiveOutputStream.close();
    }

    logger.debug("finishing the archive file " + compress);

    return compress;
}

From source file:com.qspin.qtaste.testsuite.impl.TestDataImpl.java

private void loadFile(String key, String filename) throws QTasteDataException {
    Path filePath = Paths.get(filename);
    if (!filePath.isAbsolute()) {
        filePath = Paths.get(this.getTestCaseDirectory() + File.separator + filename);
    }/*  w  w w .ja  va2 s  .com*/

    try {
        byte[] buffer = Files.readAllBytes(filePath);
        logger.debug("Loaded file: " + filePath.toString() + " size:" + buffer.length);
        hashFiles.put(key, buffer);
    } catch (IOException e) {
        throw new QTasteDataException(e.getMessage());
    }
}

From source file:org.bonitasoft.web.designer.studio.workspace.StudioWorkspaceResourceHandler.java

@Override
public void preOpen(final Path filePath) throws LockedResourceException, ResourceNotFoundException {
    try {/*w w  w. j a  va2s.co  m*/
        doPost(filePath, WorkspaceResourceEvent.PRE_OPEN);
    } catch (Exception e) {
        if (e instanceof HttpClientErrorException) {
            if (HttpStatus.LOCKED.equals(((HttpClientErrorException) e).getStatusCode())) {
                throw new LockedResourceException(filePath.toString(), e);
            }
        }
        handleResourceException(filePath, e);
    }
}

From source file:company.gonapps.loghut.dao.PostDao.java

public List<PostDto> getList(int year, int month) throws IOException, InvalidTagNameException {
    List<PostDto> posts = new LinkedList<>();

    rrwl.readLock().lock();// w w  w  .  j a  v a  2 s  .co m
    try (DirectoryStream<Path> ds = Files.newDirectoryStream(Paths.get(settingDao.getSetting("posts.directory")
            + "/" + String.format("%04d", year) + "/" + String.format("%02d", month)))) {

        for (Path path : ds) {
            Matcher matcher = postPathStringPattern.matcher(path.toString());
            if (matcher.find())
                posts.add(get(Integer.parseInt(matcher.group("year")), Integer.parseInt(matcher.group("month")),
                        Integer.parseInt(matcher.group("day")), Integer.parseInt(matcher.group("number")),
                        (matcher.group("secret").equals("s"))));
        }
    } finally {
        rrwl.readLock().unlock();
    }

    Collections.sort(posts, new PostDtoComparator());

    return posts;
}