Example usage for org.apache.commons.io FileUtils copyURLToFile

List of usage examples for org.apache.commons.io FileUtils copyURLToFile

Introduction

In this page you can find the example usage for org.apache.commons.io FileUtils copyURLToFile.

Prototype

public static void copyURLToFile(URL source, File destination) throws IOException 

Source Link

Document

Copies bytes from the URL source to a file destination.

Usage

From source file:ch.vorburger.webdriver.reporting.TestCaseReportWriter.java

/**
 * This file will create all all the required JavaScript file and CSS file
 * used for the HTML file. These files already exists in the workspace, but
 * we need them in the artifacts of the target build, hence we will have to
 * copy them out.//from   ww  w  .  j a v  a  2  s. c o  m
 */
private void createAdditionalFiles() {
    String[] files = { "index.html", "jquery-1.4.2.min.js", APPENDED_JS, "jquery-ui-1.8.5.custom.css",
            "style.css", "util.js" };
    for (String fileName : files) {
        File targetFile = new File(reportDirFile, fileName);
        if (!targetFile.exists()) {
            URL sourceFileURL = TestCaseReportWriter.class.getResource(fileName);
            if (sourceFileURL == null) {
                throw new RuntimeException("Could not find resource on classpath: " + fileName);
            }
            try {
                FileUtils.copyURLToFile(sourceFileURL, targetFile);
            } catch (IOException e) {
                throw new RuntimeException("Failed to copy resource from classpath to file: " + fileName, e);
            }
        }
    }
}

From source file:ca.weblite.codename1.ios.CodenameOneIOSBuildTask.java

/**
 * Sets up the stub file used as the entry point for the Codename One app.
 *//*from  w ww. j av  a2s .c o m*/
private void setupMainStub() throws IOException {
    File build = new File(getProject().getBaseDir(), "build");
    File generated = new File(build, "generated-src");
    if (!generated.exists()) {
        generated.mkdir();
    }

    File comD = new File(generated, "com");
    File codename1D = new File(comD, "codename1");
    File implD = new File(codename1D, "impl");
    File iosD = new File(implD, "ios");
    if (!iosD.exists()) {
        iosD.mkdirs();
    }

    File main = new File(iosD, "Main.java");
    URL mainStub = this.getClass().getResource("resources/Main.java.tpl");
    FileUtils.copyURLToFile(mainStub, main);

    Properties p = new Properties();
    File cn1Props = new File(getProject().getBaseDir(), "codenameone_settings.properties");
    p.load(new FileInputStream(cn1Props));
    StringBuilder mainClass = new StringBuilder();
    String pkgName = p.getProperty("codename1.packageName");
    if (pkgName != null && !"".equals(pkgName)) {
        mainClass.append(pkgName).append(".");
    }
    mainClass.append(p.getProperty("codename1.mainName"));

    Replace repl = (Replace) getProject().createTask("replace");
    repl.setEncoding("UTF-8");
    repl.setFile(main);
    repl.setToken("#MAIN_CLASS#");
    repl.setValue(mainClass.toString());
    repl.execute();

    repl = (Replace) getProject().createTask("replace");
    repl.setEncoding("UTF-8");
    repl.setFile(main);
    repl.setToken("#CODENAMEONE_REGISTER_NATIVE_STUBS#");
    repl.setValue("");
    repl.execute();

    getJavac().getSrcdir().add(new Path(getProject(), generated.getAbsolutePath()));

}

From source file:com.dycody.android.idealnote.utils.StorageHelper.java

/**
 * Retrieves a file from its web url// w  w w  .j  av a2  s.  c  om
 *
 * @param url
 * @return
 * @throws IOException
 */
public static File getFromHttp(String url, File file) throws IOException {
    URL imageUrl = new URL(url);
    // HttpURLConnection conn = (HttpURLConnection)imageUrl.openConnection();
    // conn.setConnectTimeout(30000);
    // conn.setReadTimeout(30000);
    // conn.setInstanceFollowRedirects(true);
    // InputStream is=conn.getInputStream();
    // OutputStream os = new FileOutputStream(f);
    // Utils.CopyStream(is, os);

    // File file = File.createTempFile("img", ".jpg");

    FileUtils.copyURLToFile(imageUrl, file);
    // os.close();
    return file;
}

From source file:com.ssn.event.controller.SSNUntaggedMediaController.java

@Override
public void mouseClicked(MouseEvent e) {
    Object mouseEventObj = e.getSource();
    if (mouseEventObj != null && mouseEventObj instanceof JLabel) {
        JLabel label = (JLabel) mouseEventObj;
        JLabel toolbarLabel = SSNHomeController.currentLabel;
        this.getHomeModel().getHomeForm().getHomeController().setIconImage(toolbarLabel,
                "/icon/tagged-untagged-media.png", "allUntagged", SSNConstants.SSN_TOOLBAR_WHITE_FONT_COLOR);
        this.getHomeModel().getHomeForm().getHomeController().setIconImage(SSNToolBar.desktopHomeLabel,
                "/icon/white_icon/home.png", "home", SSNConstants.SSN_TEXT_LABEL_YELLOW_COLOR);
        this.getHomeModel().getHomeForm().setCursor(new Cursor(Cursor.WAIT_CURSOR));
        int timoutCount = 0;
        logger.info("mouseClicked() label " + label.getName());
        switch (label.getName()) {
        case "FacebookMedia":
            untaggedMediaForm.dispose();
            String facebookMessage = "User denied for OurHive App permission on facebook.";
            if ((this.getHomeModel().getHomeForm().getFacebookAccessGrant() != null
                    && !this.getHomeModel().getHomeForm().isLoggedInFromFaceBook()
                    && getFaceBookConnection() != null)
                    && this.getHomeModel().getHomeForm().isIsSocialSearched()) {

                try {
                    File searchFolder = new File(SSNHelper.getFacebookPhotosDirPath());
                    File folder = new File(SSNHelper.getSsnDefaultDirPath());
                    File[] files = searchFolder.listFiles();
                    String defaultAlbumPath = "";
                    if (searchFolder.list().length > 0) {
                        defaultAlbumPath = (searchFolder.listFiles())[0].getAbsolutePath();
                        files = new File(defaultAlbumPath).listFiles();
                    }/*  ww w. jav  a  2  s  .  com*/

                    List<File> fileList = new ArrayList<File>();
                    for (File f : files) {
                        fileList.add(f);
                    }
                    Iterator<File> iterator = fileList.iterator();
                    while (iterator.hasNext()) {
                        File f = iterator.next();
                        boolean check = false;
                        try {
                            check = SSNDao
                                    .checkMediaExist(folder.getAbsolutePath() + File.separator + f.getName());
                        } catch (SQLException ex) {
                            //ex.printStackTrace();
                            logger.error(ex);
                        }
                        if (check) {
                            // iterator.remove();
                        }
                    }
                    File[] fileArray = new File[fileList.size()];
                    for (int i = 0; i < fileList.size(); i++) {
                        fileArray[i] = fileList.get(i);
                    }

                    //this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.setText("facebookMedia");
                    // this.getHomeModel().getHomeForm().ssnFileExplorer.m_tree.setSelectionRow(0);
                    this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.setText(defaultAlbumPath);

                    //this.getHomeModel().getHomeForm().ssnFileExplorer.m_tree.setSelectionRow(0);
                    this.getHomeModel().getHomeForm().getFileNamesToBeDeleted().clear();
                    //this.getHomeModel().getHomeForm().setCurrentSelectedFile(null);
                    SSNHelper.toggleDeleteAndShareImages(false, this.getHomeModel().getHomeForm());
                    SSNGalleryHelper contentPane = new SSNGalleryHelper(fileArray,
                            this.getHomeModel().getHomeForm());

                    contentPane.setBackground(SSNConstants.SSN_BLACK_BACKGROUND_COLOR);
                    this.getHomeModel().getHomeForm().getSsnHomeCenterPanel().removeAll();
                    this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().removeAll();

                    this.getHomeModel().getHomeForm().getSsnHomeCenterPanel().add(this.getHomeModel()
                            .getHomeForm().getScrollPane(contentPane, SSNHelper.getAlbumNameFromPath(
                                    this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.getText())));
                    this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().add(this.getHomeModel()
                            .getHomeForm()
                            .getSortPanel("Date", false, SSNHelper.getAlbumNameFromPath(
                                    this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.getText())),
                            BorderLayout.NORTH);
                    this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().add(
                            this.getHomeModel().getHomeForm().getSsnHomeCenterPanel(), BorderLayout.CENTER);
                    this.getHomeModel().getSSNMediaFolderProperties(
                            this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.getText(), fileArray);

                    renderLeftPanel();
                    this.getHomeModel().getHomeForm().revalidate();
                } catch (IOException ex) {
                    //java.util.logging.Logger.getLogger(SSNUntaggedMediaController.class.getName()).log(Level.SEVERE, null, ex);
                    logger.error(ex);
                }

            } else {

                logger.info("Facebook login user not logged in mouseClicked switch case else part");
                LoginWithFacebook.deniedPermission = false;
                AccessGrant facebookAccessGrant = getHomeModel().getHomeForm().getFacebookAccessGrant();
                if (facebookAccessGrant == null) {
                    try {

                        LoginWithFacebook loginWithFacebook = new LoginWithFacebook(null);
                        loginWithFacebook.setHomeForm(getHomeModel().getHomeForm());
                        loginWithFacebook.login();
                        boolean processFurther = false;

                        while (!processFurther) {
                            if (LoginWithFacebook.deniedPermission) {
                                break;
                            }
                            facebookAccessGrant = getHomeModel().getHomeForm().getFacebookAccessGrant();
                            if (facebookAccessGrant == null) {

                                if (timoutCount > (5 * 5000)) {
                                    LoginWithFacebook.deniedPermission = true;
                                    facebookMessage = "No response from Facebook.";
                                    SSNHttpServer.getHttpServer().stop(0);
                                    break;
                                } else {
                                    Thread.sleep(5000);
                                    timoutCount += 5000;
                                }
                            } else {
                                processFurther = true;
                            }
                        }
                    } catch (InterruptedException ex) {
                        logger.error(ex);
                        //ex.printStackTrace();
                    } catch (Exception ex) {
                        logger.error(ex);
                        //ex.printStackTrace();
                    }
                }
                if (!LoginWithFacebook.deniedPermission) {
                    //                            FacebookConnectionFactory connectionFactory = new FacebookConnectionFactory(SSNConstants.SSN_FACEBOOK_API_KEY,
                    //                                    SSNConstants.SSN_FACEBOOK_SECRET_KEY);
                    Connection<Facebook> connection = getFaceBookConnection();
                    Facebook facebook = connection.getApi();
                    MediaOperations mediaOperations = facebook.mediaOperations();

                    PagedList<Album> albums = mediaOperations.getAlbums();

                    if (albums.size() > 0) {
                        Collections.sort(albums, new Comparator<Album>() {
                            @Override
                            public int compare(final Album object1, final Album object2) {
                                return object1.getName().compareTo(object2.getName());
                            }
                        });
                    }

                    if (albums != null && !albums.isEmpty()) {
                        try {
                            List<Photo> completePhotoList = new ArrayList<Photo>();
                            String albumName = "";
                            for (Album album : albums) {
                                List<Photo> listPhoto = new ArrayList<Photo>();
                                int captured = 0;
                                do {

                                    PagingParameters pagingParameters = new PagingParameters(100, captured,
                                            null, Calendar.getInstance().getTimeInMillis());
                                    listPhoto = mediaOperations.getPhotos(album.getId(), pagingParameters);
                                    captured += listPhoto.size();
                                    completePhotoList.addAll(listPhoto);
                                    albumName = album.getName();
                                    File facebookPhotosDir = new File(SSNHelper.getFacebookPhotosDirPath()
                                            + album.getName() + File.separator);
                                    if (!facebookPhotosDir.exists()) {
                                        facebookPhotosDir.mkdir();
                                    }

                                } while (listPhoto.size() > 0);
                                break;
                            }
                            File searchFolder = new File(
                                    SSNHelper.getFacebookPhotosDirPath() + File.separator + albumName);
                            if (!searchFolder.exists()) {
                                searchFolder.mkdirs();
                            } else {
                                //delete whole directory and create new one each time  
                                FileUtils.deleteDirectory(searchFolder);
                                searchFolder.mkdir();
                            }

                            for (Photo photo : completePhotoList) {
                                try {
                                    String imageUrl = "";
                                    for (Photo.Image image : photo.getImages()) {
                                        if (image != null && image.getHeight() <= 500) {
                                            imageUrl = image.getSource();
                                            break;
                                        }
                                    }

                                    if (imageUrl.isEmpty()) {
                                        imageUrl = photo.getSource();
                                    }
                                    URL url = new URL(imageUrl);
                                    File file = new File(searchFolder.getAbsolutePath() + File.separator
                                            + photo.getId() + ".jpg");
                                    if (!file.exists()) {
                                        try {
                                            FileUtils.copyURLToFile(url, file);
                                        } catch (Exception ex) {
                                            ex.printStackTrace();
                                            logger.error(ex);
                                        }
                                    }
                                } catch (MalformedURLException ex) {
                                    //    java.util.logging.Logger.getLogger(SSNUntaggedMediaController.class.getName()).log(Level.SEVERE, null, ex);
                                    logger.error(ex);
                                }

                            }

                            this.getHomeModel().getHomeForm().setIsSocialSearched(true);
                            File[] files = searchFolder.listFiles();
                            File folder = new File(SSNHelper.getSsnDefaultDirPath());
                            List<File> tempFileList = Arrays.asList(files);

                            List<File> fileList = new ArrayList<File>();
                            fileList.addAll(tempFileList);

                            Iterator<File> iterator = fileList.iterator();
                            while (iterator.hasNext()) {
                                File f = iterator.next();
                                boolean check = false;
                                try {
                                    check = SSNDao.checkMediaExist(
                                            folder.getAbsolutePath() + File.separator + f.getName());
                                } catch (SQLException ex) {
                                    ex.printStackTrace();
                                }
                                if (check) {
                                    //iterator.remove();
                                }
                            }
                            File[] fileArray = new File[fileList.size()];
                            for (int j = 0; j < fileList.size(); j++) {
                                fileArray[j] = fileList.get(j);
                            }
                            String rootPath = SSNHelper.getSsnHiveDirPath();
                            //this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.setText("facebookMedia");
                            //this.getHomeModel().getHomeForm().ssnFileExplorer.m_tree.setSelectionRow(0);

                            this.getHomeModel().getHomeForm().ssnFileExplorer.m_display
                                    .setText(searchFolder.getAbsolutePath());
                            // this.getHomeModel().getHomeForm().getFileNamesToBeDeleted().clear();
                            // this.getHomeModel().getHomeForm().setCurrentSelectedFile(null);
                            // this.getHomeModel().getHomeForm().ssnFileExplorer.m_tree.setSelectionRow(0);
                            SSNHelper.toggleDeleteAndShareImages(false, this.getHomeModel().getHomeForm());
                            SSNGalleryHelper contentPane = new SSNGalleryHelper(fileArray,
                                    this.getHomeModel().getHomeForm());

                            contentPane.setBackground(SSNConstants.SSN_BLACK_BACKGROUND_COLOR);
                            this.getHomeModel().getHomeForm().getSsnHomeCenterPanel().removeAll();
                            this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().removeAll();

                            this.getHomeModel().getHomeForm().getSsnHomeCenterPanel()
                                    .add(this.getHomeModel().getHomeForm().getScrollPane(contentPane,
                                            SSNHelper.getAlbumNameFromPath(
                                                    this.getHomeModel().getHomeForm().ssnFileExplorer.m_display
                                                            .getText())));
                            this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel()
                                    .add(this.getHomeModel().getHomeForm().getSortPanel("Date", false,
                                            SSNHelper.getAlbumNameFromPath(
                                                    this.getHomeModel().getHomeForm().ssnFileExplorer.m_display
                                                            .getText())),
                                            BorderLayout.NORTH);
                            this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().add(
                                    this.getHomeModel().getHomeForm().getSsnHomeCenterPanel(),
                                    BorderLayout.CENTER);
                            this.getHomeModel().getSSNMediaFolderProperties(
                                    this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.getText(),
                                    fileArray);

                            renderLeftPanel();
                            this.getHomeModel().getHomeForm().revalidate();
                            // System.out.println("Show gallery  " + new Date());
                        } catch (IOException ex) {
                            logger.error(ex);
                        }

                    }
                } else {
                    SSNMessageDialogBox messageDialogBox = new SSNMessageDialogBox();
                    messageDialogBox.initDialogBoxUI(SSNDialogChoice.NOTIFICATION_DIALOG.getType(), "Alert", "",
                            facebookMessage);
                    messageDialogBox.setFocusable(true);
                }
            }
            break;
        case "InstagramMedia":
            untaggedMediaForm.dispose();
            String instagarmMessage = "User denied for OurHive App permission on instagram!";
            if ((this.getHomeModel().getHomeForm().getInstagramAccessGrant() != null
                    && !this.getHomeModel().getHomeForm().isLoggedInFromInstagram())
                    || this.getHomeModel().getHomeForm().isInstagramSearched()) {
                try {
                    // System.out.println("inside ");
                    File searchFolder = new File(
                            SSNHelper.getSsnWorkSpaceDirPath() + File.separator + "Instagram Media");
                    File folder = new File(SSNHelper.getSsnHiveDirPath() + File.separator + "InstagramMedia");
                    File[] files = searchFolder.listFiles();
                    List<File> fileList = new ArrayList<File>();
                    for (File f : files) {
                        fileList.add(f);
                    }
                    Iterator<File> iterator = fileList.iterator();
                    while (iterator.hasNext()) {
                        File f = iterator.next();
                        boolean check = false;
                        try {
                            check = SSNDao
                                    .checkMediaExist(folder.getAbsolutePath() + File.separator + f.getName());
                        } catch (SQLException ex) {
                            ex.printStackTrace();
                        }
                        if (check) {
                            // iterator.remove();
                        }
                    }
                    File[] fileArray = new File[fileList.size()];
                    for (int i = 0; i < fileList.size(); i++) {
                        fileArray[i] = fileList.get(i);
                    }

                    String rootPath = SSNHelper.getSsnHiveDirPath();

                    this.getHomeModel().getHomeForm().setCurrentSelectedFile(null);
                    this.getHomeModel().getHomeForm().ssnFileExplorer.m_tree.setSelectionPath(null);
                    this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.setText("instagramMedia");

                    //this.getHomeModel().getHomeForm().ssnFileExplorer.m_tree.setSelectionRow(0);
                    //this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.setText(searchFolder.getAbsolutePath());
                    this.getHomeModel().getHomeForm().getFileNamesToBeDeleted().clear();
                    this.getHomeModel().getHomeForm().setCurrentSelectedFile(null);
                    SSNHelper.toggleDeleteAndShareImages(false, this.getHomeModel().getHomeForm());
                    SSNGalleryHelper contentPane = new SSNGalleryHelper(fileArray,
                            this.getHomeModel().getHomeForm());

                    contentPane.setBackground(SSNConstants.SSN_BLACK_BACKGROUND_COLOR);
                    this.getHomeModel().getHomeForm().getSsnHomeCenterPanel().removeAll();
                    this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().removeAll();

                    this.getHomeModel().getHomeForm().getSsnHomeCenterPanel().add(
                            this.getHomeModel().getHomeForm().getScrollPane(contentPane, "Instagram Media"));
                    this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().add(this.getHomeModel()
                            .getHomeForm()
                            .getSortPanel("Date", false, SSNHelper.getAlbumNameFromPath(
                                    this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.getText())),
                            BorderLayout.NORTH);
                    this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().add(
                            this.getHomeModel().getHomeForm().getSsnHomeCenterPanel(), BorderLayout.CENTER);
                    this.getHomeModel().getSSNMediaFolderProperties(
                            this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.getText(), fileArray);
                    renderLeftPanel();
                    this.getHomeModel().getHomeForm().revalidate();
                } catch (IOException ex) {
                    logger.error(ex);
                }
            } else {
                try {
                    // System.out.println("cancle " + LoginWithInstagram.deniedInstagramPermission);
                    LoginWithInstagram.deniedInstagramPermission = false;
                    AccessGrant instgramAccessGrant = getHomeModel().getHomeForm().getInstagramAccessGrant();
                    if (instgramAccessGrant == null) {
                        try {

                            LoginWithInstagram loginWithInstagram = new LoginWithInstagram(
                                    getHomeModel().getHomeForm());

                            loginWithInstagram.login();
                            boolean processFurther = false;
                            while (!processFurther) {
                                if (LoginWithInstagram.deniedInstagramPermission) {
                                    break;
                                }
                                instgramAccessGrant = getHomeModel().getHomeForm().getInstagramAccessGrant();
                                if (instgramAccessGrant == null) {
                                    if (timoutCount > (5 * 5000)) {
                                        LoginWithInstagram.deniedInstagramPermission = true;
                                        instagarmMessage = "No response from instagram.";
                                        SSNHttpServer.getHttpServer().stop(0);
                                        break;
                                    } else {
                                        Thread.sleep(5000);
                                        timoutCount += 5000;
                                    }
                                } else {
                                    processFurther = true;
                                }
                            }
                        } catch (InterruptedException ex) {
                            logger.error(ex);
                        }
                    }
                    if (!LoginWithInstagram.deniedInstagramPermission) {
                        String urlString = String.format(
                                "https://api.instagram.com/v1/users/self/media/recent/?access_token=%s",
                                instgramAccessGrant.getAccessToken());
                        List<InstagramMedia> imageList = new ArrayList<>();
                        getMedia(urlString, imageList);
                        File searchFolder = new File(
                                SSNHelper.getSsnWorkSpaceDirPath() + File.separator + "Instagram Media");
                        if (!searchFolder.exists()) {
                            searchFolder.mkdirs();
                        } else {
                            //delete whole directory and create new one each time  
                            FileUtils.deleteDirectory(searchFolder);
                            searchFolder.mkdir();
                        }
                        for (InstagramMedia photo : imageList) {
                            String imageUrl = photo.getImageUrl();

                            URL url = new URL(imageUrl);
                            File file = new File(
                                    searchFolder.getAbsolutePath() + File.separator + photo.getId() + ".jpg");
                            if (!file.exists()) {
                                try {

                                    FileUtils.copyURLToFile(url, file);

                                } catch (Exception ex) {
                                    logger.error(ex);
                                }
                            }
                        }
                        this.getHomeModel().getHomeForm().setInstagramSearched(true);
                        File[] files = searchFolder.listFiles();
                        File folder = new File(SSNHelper.getSsnDefaultDirPath());
                        List<File> fileList = new ArrayList<File>();
                        for (File f : files) {
                            fileList.add(f);
                        }
                        Iterator<File> iterator = fileList.iterator();
                        while (iterator.hasNext()) {
                            File f = iterator.next();
                            boolean check = false;
                            try {
                                check = SSNDao.checkMediaExist(
                                        folder.getAbsolutePath() + File.separator + f.getName());
                            } catch (SQLException ex) {
                                ex.printStackTrace();
                                logger.error(ex);
                            }
                            if (check) {
                                //  iterator.remove();
                            }
                        }
                        File[] fileArray = new File[fileList.size()];
                        for (int j = 0; j < fileList.size(); j++) {
                            fileArray[j] = fileList.get(j);
                        }
                        String rootPath = SSNHelper.getSsnHiveDirPath();

                        this.getHomeModel().getHomeForm().setCurrentSelectedFile(null);
                        this.getHomeModel().getHomeForm().ssnFileExplorer.m_tree.setSelectionPath(null);
                        this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.setText("instagramMedia");

                        //this.getHomeModel().getHomeForm().ssnFileExplorer.m_tree.setSelectionRow(0);
                        // this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.setText(searchFolder.getAbsolutePath());
                        this.getHomeModel().getHomeForm().getFileNamesToBeDeleted().clear();
                        //this.getHomeModel().getHomeForm().setCurrentSelectedFile(null);

                        SSNHelper.toggleDeleteAndShareImages(false, this.getHomeModel().getHomeForm());
                        SSNGalleryHelper contentPane = new SSNGalleryHelper(fileArray,
                                this.getHomeModel().getHomeForm());

                        contentPane.setBackground(SSNConstants.SSN_BLACK_BACKGROUND_COLOR);
                        this.getHomeModel().getHomeForm().getSsnHomeCenterPanel().removeAll();
                        this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().removeAll();

                        this.getHomeModel().getHomeForm().getSsnHomeCenterPanel().add(this.getHomeModel()
                                .getHomeForm().getScrollPane(contentPane, "Instagram Media"));
                        this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().add(this.getHomeModel()
                                .getHomeForm()
                                .getSortPanel("Date", false, SSNHelper.getAlbumNameFromPath(
                                        this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.getText())),
                                BorderLayout.NORTH);
                        this.getHomeModel().getHomeForm().getSsnHomeCenterMainPanel().add(
                                this.getHomeModel().getHomeForm().getSsnHomeCenterPanel(), BorderLayout.CENTER);
                        this.getHomeModel().getSSNMediaFolderProperties(
                                this.getHomeModel().getHomeForm().ssnFileExplorer.m_display.getText(),
                                fileArray);

                        renderLeftPanel();
                        this.getHomeModel().getHomeForm().revalidate();
                    } else {
                        SSNMessageDialogBox messageDialogBox = new SSNMessageDialogBox();
                        messageDialogBox.initDialogBoxUI(SSNDialogChoice.NOTIFICATION_DIALOG.getType(), "Alert",
                                "", instagarmMessage);
                        messageDialogBox.setFocusable(true);
                    }

                } catch (ProtocolException ex) {
                    // ex.printStackTrace();
                    logger.error(ex);
                    //             java.util.logging.Logger.getLogger(SSNUntaggedMediaController.class.getName()).log(Level.SEVERE, null, ex);
                } catch (IOException ex) {
                    //ex.printStackTrace();
                    logger.error(ex);
                    //         java.util.logging.Logger.getLogger(SSNUntaggedMediaController.class.getName()).log(Level.SEVERE, null, ex);
                }

            }
            break;
        case "deviceMedia":
            untaggedMediaForm.dispose();
            this.getHomeModel().findTagUntaggedMedia();
            break;
        case "Cancel":
            untaggedMediaForm.dispose();
        }
        SSNHomeController.isUnTaggedOpen = false;
        untaggedMediaForm.dispose();
        this.getHomeModel().getHomeForm().setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }
}

From source file:com.t3.persistence.PersistenceUtil.java

public static Token loadToken(URL url) throws IOException {
    // Create a temporary file from the downloaded URL
    GUID guid = new GUID();
    File newFile = new File(PackedFile.getTmpDir(guid.toString()), guid + ".url");
    FileUtils.copyURLToFile(url, newFile);
    Token token = loadToken(newFile);/*  w ww .j  a v  a 2s  .  co m*/
    newFile.delete();
    return token;
}

From source file:com.microsoft.intellij.AzurePlugin.java

private void extractJobViewResource() {
    File indexRootFile = new File(
            PluginUtil.getPluginRootDirectory() + File.separator + "com.microsoft.hdinsight");

    if (isFirstInstallationByVersion() || isDebugModel()) {
        if (indexRootFile.exists()) {
            try {
                FileUtils.deleteDirectory(indexRootFile);
            } catch (IOException e) {
                LOG.error("delete HDInsight job view folder error", e);
            }//from ww  w . j  av  a 2s  .  c  o m
        }
    }

    URL url = AzurePlugin.class.getResource(HTML_ZIP_FILE_NAME);
    if (url != null) {
        File toFile = new File(indexRootFile.getAbsolutePath(), HTML_ZIP_FILE_NAME);
        try {
            FileUtils.copyURLToFile(url, toFile);
            unzip(toFile.getAbsolutePath(), toFile.getParent());
        } catch (IOException e) {
            LOG.error("Extract Job View Folder", e);
        }
    } else {
        LOG.error("Can't find HDInsight job view zip package");
    }
}

From source file:com.htmlhifive.pitalium.core.io.FilePersisterTest.java

/**
 * ???/* www  .  j  a v a2s  .co m*/
 */
@Test
public void testLoadScreenshot_selector() throws Exception {
    File file = new File(
            BASE_DIRECTORY + "/testId/testClass/testMethod_scId_WINDOWS_firefox_38_CSS_SELECTOR_main_[0].png");

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("platform", "WINDOWS");
    map.put("browserName", "firefox");
    map.put("version", "38");

    PtlCapabilities capabilities = new PtlCapabilities(map);
    IndexDomSelector selector = new IndexDomSelector(SelectorType.CSS_SELECTOR, "main", 0);
    PersistMetadata metadata = new PersistMetadata("testId", "testClass", "testMethod", "scId", selector, null,
            capabilities);

    FileUtils.copyURLToFile(getClass().getResource("FilePersister_Image.png"), file);

    BufferedImage expected = ImageIO.read(getClass().getResource("FilePersister_Image.png"));
    BufferedImage actual = persister.loadScreenshot(metadata);

    assertArrayEquals(toRGB(expected), toRGB(actual));
}

From source file:net.doubledoordev.backend.server.Server.java

/**
 * Downloads and uses specific forge installer
 *//*from   w ww .j  a v  a2 s.  co m*/
public void installForge(final IMethodCaller methodCaller, final String name) {
    if (getOnline())
        throw new ServerOnlineException();
    final String version = Helper.getForgeVersionForName(name);
    if (version == null)
        throw new IllegalArgumentException("Forge with ID " + name + " not found.");
    if (downloading)
        throw new IllegalStateException("Already downloading something.");
    if (!isCoOwner(methodCaller.getUser()))
        throw new AuthenticationException();
    final Server instance = this;
    new Thread(new Runnable() {
        @Override
        public void run() {
            downloading = true;
            try {
                // delete old files
                for (File file : folder.listFiles(ACCEPT_MINECRAFT_SERVER_FILTER))
                    file.delete();
                for (File file : folder.listFiles(ACCEPT_FORGE_FILTER))
                    file.delete();

                // download new files
                String url = Constants.FORGE_INSTALLER_URL.replace("%ID%", version);
                String forgeName = url.substring(url.lastIndexOf('/'));
                File forge = new File(folder, forgeName);
                FileUtils.copyURLToFile(new URL(url), forge);

                // run installer
                List<String> arguments = new ArrayList<>();

                arguments.add(Constants.getJavaPath());
                arguments.add("-Xmx1G");

                arguments.add("-jar");
                arguments.add(forge.getName());

                arguments.add("--installServer");

                ProcessBuilder builder = new ProcessBuilder(arguments);
                builder.directory(folder);
                builder.redirectErrorStream(true);
                final Process process = builder.start();
                printLine(arguments.toString());
                BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
                String line;
                while ((line = reader.readLine()) != null) {
                    methodCaller.sendMessage(line);
                    printLine(line);
                }

                try {
                    process.waitFor();
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }

                for (String name : folder.list(ACCEPT_FORGE_FILTER))
                    getJvmData().jarName = name;

                forge.delete();

                methodCaller.sendDone();
                printLine("Forge installer done.");

                instance.update();
            } catch (IOException e) {
                printLine("##################################################################");
                printLine("Error installing a new forge version (version " + version + ")");
                printLine(e.toString());
                printLine("##################################################################");
                e.printStackTrace();
            }
            downloading = false;
        }
    }, getID() + "-forge-installer").start();
}

From source file:cz.cas.lib.proarc.common.export.mets.JhoveUtility.java

/**
 * Copy the Jhove configuration file to a temporary file.
 *
 * @return the {@link File} where the Jhove configuration was saved.
 *
 *//*  w  w  w  .  j  a va 2 s  .c o m*/
private static File createJhoveConfigurationFile(File configFolder) throws MetsExportException {
    URL jhoveConf = JhoveUtility.class.getResource(JHOVE_CONFIG_NAME);
    URL jhoveConfXsd = JhoveUtility.class.getResource("jhoveConfig.xsd");
    try {
        File jhoveConfFile = new File(configFolder, JHOVE_CONFIG_NAME);
        LOG.log(Level.FINE, "JHOVE configuration file " + jhoveConfFile);
        if (!jhoveConfFile.exists()) {
            FileUtils.copyURLToFile(jhoveConf, jhoveConfFile);
        }
        File xsdFile = new File(jhoveConfFile.getParent(), "jhoveConfig.xsd");
        if (!xsdFile.exists()) {
            FileUtils.copyURLToFile(jhoveConfXsd, xsdFile);
        }
        return jhoveConfFile;
    } catch (IOException ex) {
        throw new MetsExportException("Unable to create jHove config file", false, ex);
    }
}

From source file:com.htmlhifive.pitalium.core.io.FilePersisterTest.java

/**
 * ???/*w ww.  j av a 2 s.  c o  m*/
 */
@Test
public void testLoadScreenshot_rectangle() throws Exception {
    File file = new File(
            BASE_DIRECTORY + "/testId/testClass/testMethod_scId_WINDOWS_firefox_38_rect_0_10_100_110.png");

    Map<String, Object> map = new HashMap<String, Object>();
    map.put("platform", "WINDOWS");
    map.put("browserName", "firefox");
    map.put("version", "38");

    PtlCapabilities capabilities = new PtlCapabilities(map);
    RectangleArea rectangle = new RectangleArea(0d, 10d, 100d, 110d);
    PersistMetadata metadata = new PersistMetadata("testId", "testClass", "testMethod", "scId", null, rectangle,
            capabilities);

    FileUtils.copyURLToFile(getClass().getResource("FilePersister_Image.png"), file);

    BufferedImage expected = ImageIO.read(getClass().getResource("FilePersister_Image.png"));
    BufferedImage actual = persister.loadScreenshot(metadata);

    assertArrayEquals(toRGB(expected), toRGB(actual));
}