Example usage for java.io File setWritable

List of usage examples for java.io File setWritable

Introduction

In this page you can find the example usage for java.io File setWritable.

Prototype

public boolean setWritable(boolean writable) 

Source Link

Document

A convenience method to set the owner's write permission for this abstract pathname.

Usage

From source file:shape.ShapeContainer.java

protected void writeLinesToPDBFile(List<String> listOfLines, String fileName, AlgoParameters algoParameters) {

    String pathForThisFile = algoParameters.getPATH_TO_RESULT_FILES();
    String fileNameForThisFile = fileName + ".ent.gz";

    try {/*w  w w  .jav  a2  s. c  o  m*/
        File file = new File(pathForThisFile + fileNameForThisFile);
        if (file.exists()) {
            file.setWritable(true);
            file.delete();
        }

        BufferedWriter outputFile = new BufferedWriter(new OutputStreamWriter(
                new GZIPOutputStream(new FileOutputStream(pathForThisFile + fileNameForThisFile))));
        for (String str : listOfLines) {
            outputFile.write(str + "\n");
        }
        outputFile.write("END");
        outputFile.close();

    } catch (IOException e) {
        //System.out.println("Failure: in writting PDB file");
        //e.printStackTrace();
    }
}

From source file:com.gamerking195.dev.lametric.RestfulWriter.java

@SuppressWarnings("ResultOfMethodCallIgnored")
private void createFiles() {
    if (debug) {//from   w  ww .j  av a  2s.  com
        System.out.println("");
        System.out.println("=================BEGIN DEBUG=================");
        System.out.println("");
    }
    File subDirectories = new File(filePath);
    subDirectories.mkdirs();

    //MINESWINE APP
    File msFile = new File(filePath + "/mineswineapp.json");

    if (msFile.exists())
        msFile.delete();

    try {
        msFile.createNewFile();

        msFile.setWritable(true);
        msFile.setReadable(true);
        FileWriter writer = new FileWriter(msFile);

        String mineswineStatus = getMineswineApp();

        if (debug) {
            System.out.println("MINESWINE: ");
            System.out.println(mineswineStatus);
        }

        writer.write(mineswineStatus);
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (debug) {
        System.out.println("");
    }

    //MOJANG APP
    File mcFile = new File(filePath + "/mojangapp.json");

    if (mcFile.exists())
        mcFile.delete();

    try {
        mcFile.createNewFile();

        mcFile.setWritable(true);
        mcFile.setReadable(true);

        FileWriter writer = new FileWriter(mcFile);

        if (debug)
            System.out.println("SERVICES: ");

        String mojangStatus = getMojangApp();

        if (debug) {
            System.out.println("MOJANG: ");
            System.out.println(mojangStatus);
        }

        writer.write(mojangStatus);
        writer.close();
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (debug) {
        System.out.println("");
        System.out.println("=================END DEBUG=================");
    }
}

From source file:playRepository.SVNRepository.java

public boolean move(String srcProjectOwner, String srcProjectName, String desrProjectOwner,
        String destProjectName) {
    File src = new File(getRepoPrefix() + srcProjectOwner + "/" + srcProjectName);
    File dest = new File(getRepoPrefix() + desrProjectOwner + "/" + destProjectName);
    src.setWritable(true);

    try {/*from   www. j a  v a2s.  c  om*/
        if (src.exists()) {
            FileUtils.moveDirectory(src, dest);
        }
        return true;
    } catch (IOException e) {
        play.Logger.error("Move Failed", e);
        return false;
    }
}

From source file:hudson.Util.java

/**
 * Makes the given file writable by any means possible.
 *//*from www  .j  ava 2s .  co  m*/
@IgnoreJRERequirement
private static void makeWritable(File f) {
    // try chmod. this becomes no-op if this is not Unix.
    try {
        Chmod chmod = new Chmod();
        chmod.setProject(new Project());
        chmod.setFile(f);
        chmod.setPerm("u+w");
        chmod.execute();
    } catch (BuildException e) {
        LOGGER.log(Level.INFO, "Failed to chmod " + f, e);
    }

    // also try JDK6-way of doing it.
    try {
        f.setWritable(true);
    } catch (NoSuchMethodError e) {
        // not JDK6
    }

    try {// try libc chmod
        POSIX posix = PosixAPI.get();
        String path = f.getAbsolutePath();
        FileStat stat = posix.stat(path);
        posix.chmod(path, stat.mode() | 0200); // u+w
    } catch (Throwable t) {
        LOGGER.log(Level.FINE, "Failed to chmod(2) " + f, t);
    }

}

From source file:com.emarsys.dyson.storage.DefaultDysonStorage.java

/**
 * Creates the directory with the passed filename if it's not
 * already present.// w  w  w. j  a v  a  2 s .  c  o  m
 * 
 * @param pathToDir - the path to the directory
 * @throws DysonException - if it was not possible to create a
 *       writable directory with the passed path.
 */
protected void createDirsIfNotPresent(String pathToDir) throws DysonException {
    File dir = new File(pathToDir);
    if (!dir.exists()) {
        log.debug("creating dir(s) \'{}\'", pathToDir);
        dir.mkdirs();
        dir.setReadable(true);
        dir.setWritable(true);
    }

    boolean isWritableDirectoryPresent = dir.exists() && dir.isDirectory() && dir.canRead() && dir.canWrite();

    if (!isWritableDirectoryPresent) {
        throw new DysonException("Was not able to create directory \'" + pathToDir + "\'");
    }
}

From source file:com.timothy.android.api.fragment.PageFragmentNew.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    //get activity and SharedPreferences
    activity = (SlidingActivity) getActivity();
    sp = activity.getSharedPreferences("AndroidAPISP", 0);
    mContext = activity.getApplicationContext();

    View mView = inflater.inflate(R.layout.view_pager_text_new, null);
    lineLayout = (LinearLayout) mView.findViewById(R.id.lineLayout);

    currentIndex = SPUtil.getIntegerFromSP(SPUtil.CURRENT_INDEX, sp);
    Log.i(LOG_TAG, "currentIndex:" + String.valueOf(currentIndex));

    showLeft = (ImageView) mView.findViewById(R.id.showLeft);
    showRight = (ImageView) mView.findViewById(R.id.showRight);
    //      mPager = (ViewPager) mView.findViewById(R.id.pager);
    progressBar = (ProgressBar) mView.findViewById(R.id.loading_spinner);

    //      String firstLoad = SPUtil.getFromSP(SPUtil.FIRST_LOAD_FLAG, sp);
    //      if(currentIndex == -1){
    if (currentIndex == -1) {
        //         HomeFragment homeFrag = new HomeFragment();
        //         pagerItemList.add(homeFrag);
        //         setAdapter();

        SPUtil.save2SP(SPUtil.FIRST_LOAD_FLAG, "No", sp);

    } else {/*from   www .  ja  v  a  2  s. c om*/

        int branchIndex = SPUtil.getIntegerFromSP(SPUtil.CURRENT_BRANCH_INDEX, sp);
        Log.i(LOG_TAG, "branchIndex:" + String.valueOf(branchIndex));

        contentsArray = activity.filterBranch(branchIndex);
        contents = ContentUtil.getContentsById(contentsArray, currentIndex);

        if (contents != null) {
            Log.i(LOG_TAG, "contents:" + contents);
            contentArray = contents.split(",");
            contentId = contentArray[0];
            contentLevel = contentArray[1];
            contentSuperId = contentArray[2];
            contentName = contentArray[3];
            contentURL = contentArray[4];

            //super content
            String superContents = ContentUtil.getSuperContentsById(contentsArray, currentIndex);
            String appPath = SPUtil.getFromSP(SPUtil.APP_HOME_PATH, sp);
            String branchName = SPUtil.getFromSP(SPUtil.BRANCH_PATH_NAME, sp);
            Log.i(LOG_TAG, "superContents:" + superContents);
            Log.i(LOG_TAG, "appPath:" + appPath);
            Log.i(LOG_TAG, "branchName:" + branchName);

            baseFolder = appPath + File.separator + branchName;

            //second path
            String branchPath = appPath + File.separator + branchName;
            File subPathFold = new File(branchPath);
            if (!subPathFold.isDirectory())
                subPathFold.mkdir();
            if (!subPathFold.canWrite())
                subPathFold.setWritable(true);

            String contentPath = branchPath + File.separator + StringUtil.rmvSpace(contentName) + ".xml";
            Log.i(LOG_TAG, "contentPath:" + contentPath);

            boolean flag3GWifi = SPUtil.getBooleanFromSP(SPUtil.SP_KEY_SYNC_FLAG, sp);

            //            if(new File(contentPath).exists()){
            ////               Log.i(LOG_TAG,"exists load local content");
            ////               new ParseData().execute(new String[] { contentURL, contentPath , XPATH });
            //            }else{
            //               Log.i(LOG_TAG,"not exists,should download by network");
            //            }

            //            if(NetWorkUtil.isNetworkAvailable(mContext)){
            //               if(NetWorkUtil.is3G(mContext) || NetWorkUtil.isWifi(mContext)){
            new GetData().execute(new String[] { contentURL, contentPath, XPATH, branchPath });
            //               }
            //            }
        } else {
            titleTV.setText("Error,try again!");
        }
    }

    return mView;
}

From source file:hudson.Util.java

/**
 * Makes the given file writable by any means possible.
 *///from  w w w .  j  a  v  a 2s .  co m
private static void makeWritable(File f) {
    // try chmod. this becomes no-op if this is not Unix.
    try {
        Chmod chmod = new Chmod();
        chmod.setProject(new Project());
        chmod.setFile(f);
        chmod.setPerm("u+w");
        chmod.execute();
    } catch (BuildException e) {
        LOGGER.log(Level.INFO, "Failed to chmod " + f, e);
    }

    // also try JDK6-way of doing it.
    try {
        f.setWritable(true);
    } catch (NoSuchMethodError e) {
        // not JDK6
    }

    if (!Functions.isWindows()) {
        try {
            NativeUtils.getInstance().makeFileWritable(f);
        } catch (NativeAccessException exc) {
            LOGGER.log(Level.FINE, "Failed to chmod(2) " + f, exc);
        }
    }
}

From source file:com.timothy.android.api.fragment.ViewPagesFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    Log.i(LOG_TAG, "onCreateView()...");
    activity = (SlidingActivity) getActivity();
    sp = activity.getSharedPreferences("AndroidAPISP", 0);
    mContext = activity.getApplicationContext();
    View mView = inflater.inflate(R.layout.view_pagers, null);
    showLeft = (ImageView) mView.findViewById(R.id.showLeft);
    titleTV = (TextView) mView.findViewById(R.id.titleTextView);
    titleTV.setOnClickListener(new View.OnClickListener() {
        @Override// w  ww  .  j  a va  2s.  c  om
        public void onClick(View v) {
            Log.i(LOG_TAG, "titleTV onclicked...");
        }
    });

    currentIndex = SPUtil.getIntegerFromSP(SPUtil.CURRENT_INDEX, sp);
    Log.i(LOG_TAG, "currentIndex:" + String.valueOf(currentIndex));

    showRight = (ImageView) mView.findViewById(R.id.showRight);
    mPager = (ViewPager) mView.findViewById(R.id.pager);
    progressBar = (ProgressBar) mView.findViewById(R.id.loading_spinner);

    String firstLoad = SPUtil.getFromSP(SPUtil.FIRST_LOAD_FLAG, sp);
    //      if(currentIndex == -1){
    if (firstLoad == null || currentIndex == -1) {
        HomeFragment homeFrag = new HomeFragment();
        pagerItemList.add(homeFrag);
        setAdapter();

        SPUtil.save2SP(SPUtil.FIRST_LOAD_FLAG, "No", sp);

    } else {

        int branchIndex = SPUtil.getIntegerFromSP(SPUtil.CURRENT_BRANCH_INDEX, sp);
        Log.i(LOG_TAG, "branchIndex:" + String.valueOf(branchIndex));

        contentsArray = activity.filterBranch(branchIndex);
        contents = ContentUtil.getContentsById(contentsArray, currentIndex);

        if (contents != null) {
            Log.i(LOG_TAG, "contents:" + contents);
            contentArray = contents.split(",");
            contentId = contentArray[0];
            contentLevel = contentArray[1];
            contentSuperId = contentArray[2];
            contentName = contentArray[3];
            contentURL = contentArray[4];

            //super content
            String superContents = ContentUtil.getSuperContentsById(contentsArray, currentIndex);
            Log.i(LOG_TAG, "superContents:" + superContents);
            //            String[] superContentArray = superContents.split(",");
            String appPath = SPUtil.getFromSP(SPUtil.APP_HOME_PATH, sp);
            String branchName = SPUtil.getFromSP(SPUtil.BRANCH_PATH_NAME, sp);
            Log.i(LOG_TAG, "appPath:" + appPath);
            Log.i(LOG_TAG, "branchName:" + branchName);

            //second path
            String branchPath = appPath + File.separator + branchName;
            File subPathFold = new File(branchPath);
            if (!subPathFold.isDirectory())
                subPathFold.mkdir();
            if (!subPathFold.canWrite())
                subPathFold.setWritable(true);

            String contentPath = branchPath + File.separator + StringUtil.rmvSpace(contentName) + ".xml";
            Log.i(LOG_TAG, "contentPath:" + contentPath);

            boolean flag3GWifi = SPUtil.getBooleanFromSP(SPUtil.SP_KEY_SYNC_FLAG, sp);

            if (new File(contentPath).exists()) {
                Log.i(LOG_TAG, "exists load local content");
                new ParseData().execute(new String[] { contentURL, contentPath, XPATH });
            } else {
                Log.i(LOG_TAG, "not exists,should download by network");
                if (NetWorkUtil.isNetworkAvailable(mContext)) {
                    if (NetWorkUtil.is3G(mContext) || NetWorkUtil.isWifi(mContext)) {
                        new GetData().execute(new String[] { contentURL, contentPath, XPATH, branchPath });
                    } else {
                        if (flag3GWifi) {
                            errorFlag = true;
                            pagerItemList.add(PageFragment.newInstance(-1, -1, 2));
                            setAdapter();
                        } else {
                            new GetData().execute(new String[] { contentURL, contentPath, XPATH, branchPath });
                        }
                    }
                } else {
                    errorFlag = true;
                    pagerItemList.add(PageFragment.newInstance(-1, -1, 1));
                    setAdapter();
                }
            }
        } else {
            titleTV.setText("Error,try again!");
        }
    }

    if (errorFlag) {
        titleTV.setText("Error");
    }

    //close ad
    adView = (com.google.ads.AdView) mView.findViewById(R.id.adView);
    closeAD = (ImageView) mView.findViewById(R.id.closeAD);
    if (adView.getVisibility() == View.VISIBLE) {
        closeAD.setVisibility(View.VISIBLE);
    } else {
        closeAD.setVisibility(View.GONE);
    }
    closeAD.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            adView.setVisibility(View.GONE);
        }
    });

    return mView;
}

From source file:se.sics.kompics.p2p.experiment.dsl.SimulationScenario.java

/**
 * Copy resources.// w  ww . ja va  2  s  .c om
 * 
 * @param classPath
 *            the class path
 * @param boot
 *            the boot
 * 
 * @throws IOException
 *             Signals that an I/O exception has occurred.
 */
private static void copyResources(String classPath, String boot) throws IOException {
    LinkedList<String> resources = getAllResources(classPath);

    String target = directory;
    if (boot == null) {
        target += "application";
        logger.info("Copying application resources to:" + target);
    } else {
        target += boot;
        logger.info("Copying bootstrap resources to:" + target);
    }

    int count = resources.size();
    long start = System.currentTimeMillis();

    for (final String resourceName : resources) {
        InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceName);

        String targetFile = target + "/" + resourceName;
        File dir = new File(new File(targetFile).getParent());
        if (!dir.exists()) {
            dir.mkdirs();
            dir.setWritable(true);
        }
        OutputStream os = new FileOutputStream(targetFile);
        byte buffer[] = new byte[65536];
        int len;

        long ms = System.currentTimeMillis();

        // copy the resource
        while ((len = is.read(buffer)) > 0) {
            os.write(buffer, 0, len);
        }
        is.close();
        os.close();

        ms = System.currentTimeMillis() - ms;
        logger.trace(
                "Copying " + resourceName + " to " + (target + "/" + resourceName) + " - took " + ms + "ms.");
    }

    long stop = System.currentTimeMillis();
    logger.info("It took " + (stop - start) + "ms to copy " + count + " resources.");
}

From source file:org.apache.flink.statistics.model.SimpleStatisticsStore.java

public void shutdown() throws IOException {
    if (path != null) {
        File f = new File(path);
        File parent_directory = f.getParentFile();
        if (null != parent_directory) {
            parent_directory.mkdirs();//from ww  w .  j av a 2 s .co  m
        }
        if (f.isDirectory()) {
            if (path.endsWith("/")) {
                f = new File(path.substring(0, path.lastIndexOf("/") + 1) + "simpleStatStore.db");
            } else {
                f = new File(path + "/simpleStatStore.db");
            }
        }
        f.createNewFile();
        if (!f.canWrite() && !f.setWritable(true)) {
            LOG.error("no permission to write index to file: " + path);
            throw new IOException();
        }
        Output out = new Output(new FileOutputStream(f));
        Kryo kryo = new Kryo();
        kryo.setRegistrationRequired(false);
        kryo.writeClassAndObject(out, statistics);
        out.close();
    }
}