<commit_before>/**
 * Appcelerator Titanium Mobile
 * Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 */
package ti.modules.titanium.filesystem;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.appcelerator.titanium.TiBlob;
import org.appcelerator.titanium.TiContext;
import org.appcelerator.titanium.TiProxy;
import org.appcelerator.titanium.io.TiBaseFile;
import org.appcelerator.titanium.io.TiFileFactory;
import org.appcelerator.titanium.util.TiFileHelper2;

import android.net.Uri;

public class FileProxy extends TiProxy
{

	String path;
	TiBaseFile tbf; // The base file object.

	public static <T>
	String join(final Collection<T> objs, final String delimiter) {
	    if (objs == null || objs.isEmpty())
	        return "";
	    Iterator<T> iter = objs.iterator();
	    // remove the following two lines, if you expect the Collection will behave well
	    if (!iter.hasNext())
	        return "";
	    StringBuffer buffer = new StringBuffer(String.valueOf(iter.next()));
	    while (iter.hasNext())
	        buffer.append(delimiter).append(String.valueOf(iter.next()));
	    return buffer.toString();
	}

	public FileProxy(TiContext tiContext, String[] parts) {
		super(tiContext);

		//String path = getTiContext().resolveUrl(join(Arrays.asList(parts), "/"));
		String scheme = "appdata-private://";
		String path = null;
		Uri uri = Uri.parse(parts[0]);
		if (uri.getScheme() != null) {
			scheme = uri.getScheme() + ":";
			ArrayList<String> pb = new ArrayList<String>();
			String s = parts[0].substring(scheme.length() + 2);
			if (s != null && s.length() > 0) {
				pb.add(s);
			}
			for (int i = 1; i < parts.length; i++) {
				pb.add(parts[i]);
			}
			String[] newParts = pb.toArray(new String[pb.size()]);
			path = TiFileHelper2.joinSegments(newParts);
			if (!path.startsWith("..") || !path.startsWith("/")) {
				path = "/" + path;
			}
			pb.clear();
		} else {
			path = TiFileHelper2.joinSegments(parts);
		}
		path = getTiContext().resolveUrl(scheme, path);
		tbf = TiFileFactory.createTitaniumFile(tiContext, new String[] { path }, false);
	}

	private FileProxy(TiContext tiContext, TiBaseFile tbf) {
		super(tiContext);
		this.tbf = tbf;
	}

	public TiBaseFile getBaseFile() {
		return tbf;
	}

	public boolean isFile() {
		return tbf.isFile();
	}

	public boolean isDirectory() {
		return tbf.isDirectory();
	}

	public boolean getReadonly() {
		return tbf.isReadonly();
	}

	public boolean getWritable() {
		return tbf.isWriteable();
	}

	public boolean copy (String destination) throws IOException {
		return tbf.copy(destination);
	}

	public void createDirectory(boolean recursive) {
		tbf.createDirectory(recursive);
	}

	public boolean deleteDirectory(boolean recursive) {
		return tbf.deleteDirectory(recursive);
	}

	public boolean deleteFile() {
		return tbf.deleteFile();
	}

	public boolean exists() {
		return tbf.exists();
	}

	public String extension() {
		return tbf.extension();
	}

	public boolean getSymbolicLink() {
		return tbf.isSymbolicLink();
	}

	public boolean getExecutable() {
		return tbf.isExecutable();
	}<commit_msg>[#671 state:resolved] Added ability to take noarg parameter. Defaults to recursive == true<commit_after>/**
 * Appcelerator Titanium Mobile
 * Copyright (c) 2009-2010 by Appcelerator, Inc. All Rights Reserved.
 * Licensed under the terms of the Apache Public License
 * Please see the LICENSE included with this distribution for details.
 */
package ti.modules.titanium.filesystem;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.appcelerator.titanium.TiBlob;
import org.appcelerator.titanium.TiContext;
import org.appcelerator.titanium.TiProxy;
import org.appcelerator.titanium.io.TiBaseFile;
import org.appcelerator.titanium.io.TiFileFactory;
import org.appcelerator.titanium.util.TiConvert;
import org.appcelerator.titanium.util.TiFileHelper2;

import android.net.Uri;

public class FileProxy extends TiProxy
{

	String path;
	TiBaseFile tbf; // The base file object.

	public static <T>
	String join(final Collection<T> objs, final String delimiter) {
	    if (objs == null || objs.isEmpty())
	        return "";
	    Iterator<T> iter = objs.iterator();
	    // remove the following two lines, if you expect the Collection will behave well
	    if (!iter.hasNext())
	        return "";
	    StringBuffer buffer = new StringBuffer(String.valueOf(iter.next()));
	    while (iter.hasNext())
	        buffer.append(delimiter).append(String.valueOf(iter.next()));
	    return buffer.toString();
	}

	public FileProxy(TiContext tiContext, String[] parts) {
		super(tiContext);

		//String path = getTiContext().resolveUrl(join(Arrays.asList(parts), "/"));
		String scheme = "appdata-private://";
		String path = null;
		Uri uri = Uri.parse(parts[0]);
		if (uri.getScheme() != null) {
			scheme = uri.getScheme() + ":";
			ArrayList<String> pb = new ArrayList<String>();
			String s = parts[0].substring(scheme.length() + 2);
			if (s != null && s.length() > 0) {
				pb.add(s);
			}
			for (int i = 1; i < parts.length; i++) {
				pb.add(parts[i]);
			}
			String[] newParts = pb.toArray(new String[pb.size()]);
			path = TiFileHelper2.joinSegments(newParts);
			if (!path.startsWith("..") || !path.startsWith("/")) {
				path = "/" + path;
			}
			pb.clear();
		} else {
			path = TiFileHelper2.joinSegments(parts);
		}
		path = getTiContext().resolveUrl(scheme, path);
		tbf = TiFileFactory.createTitaniumFile(tiContext, new String[] { path }, false);
	}

	private FileProxy(TiContext tiContext, TiBaseFile tbf) {
		super(tiContext);
		this.tbf = tbf;
	}

	public TiBaseFile getBaseFile() {
		return tbf;
	}

	public boolean isFile() {
		return tbf.isFile();
	}

	public boolean isDirectory() {
		return tbf.isDirectory();
	}

	public boolean getReadonly() {
		return tbf.isReadonly();
	}

	public boolean getWritable() {
		return tbf.isWriteable();
	}

	public boolean copy (String destination) throws IOException {
		return tbf.copy(destination);
	}

	public void createDirectory(Object arg) {
		boolean recursive = true;

		if (arg != null) {
			recursive = TiConvert.toBoolean(arg);
		}
		tbf.createDirectory(recursive);
	}

	public boolean deleteDirectory(Object arg) {
		boolean recursive = true;

		if (arg != null) {
			recursive = TiConvert.toBoolean(arg);
		}
		return tbf.deleteDirectory(recursive);
	}

	public boolean deleteFile() {
		return tbf.deleteFile();
	}

	public boolean exists() {
		return tbf.exists();
	}

	public String extension() {
		return tbf.extension();
	}

	public boolean getSymbolicLink() {
		return tbf.isSymbolicLink();
	}

	public boolean getExecutable() {
		return tbf.isExecutable();
	}
{'fraction_non_alphanumeric': 0.13410071942446042, 'fraction_numerical': 0.005035971223021582, 'mean_word_length': 3.929787234042553, 'pattern_counts': {'":': 2, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7592358', 'n_tokens_mistral': 2478, 'n_tokens_neox': 2236, 'n_words': 551}