Java Code Examples for jcifs.smb.SmbFile#length()

The following examples show how to use jcifs.smb.SmbFile#length() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HFile.java    From PowerFileExplorer with GNU General Public License v3.0 6 votes vote down vote up
/**
 * @deprecated use {@link #length(Context)} to handle content resolvers
 * @return
 */
public long length() {
    long s = 0L;
    switch (mode) {
        case SMB:
            SmbFile smbFile = getSmbFile();
            if (smbFile != null)
                try {
                    s = smbFile.length();
                } catch (SmbException e) {
                }
            return s;
        case FILE:
            s = new File(path).length();
            return s;
        case ROOT:
            BaseFile baseFile = generateBaseFileFromParent();
            if (baseFile != null) return baseFile.size;
            break;
    }
    return s;
}
 
Example 2
Source File: SambaSenderOld.java    From iaf with Apache License 2.0 6 votes vote down vote up
private XmlBuilder getFileAsXmlBuilder(SmbFile file) throws SmbException {
	XmlBuilder fileXml = new XmlBuilder("file");
	fileXml.addAttribute("name", file.getName());
	long fileSize = file.length();
	fileXml.addAttribute("size", "" + fileSize);
	fileXml.addAttribute("fSize", "" + Misc.toFileSize(fileSize, true));
	fileXml.addAttribute("directory", "" + file.isDirectory());
	fileXml.addAttribute("canonicalName", file.getCanonicalPath());

	// Get the modification date of the file
	Date modificationDate = new Date(file.lastModified());
	//add date
	String date = DateUtils.format(modificationDate, DateUtils.FORMAT_DATE);
	fileXml.addAttribute("modificationDate", date);

	// add the time
	String time = DateUtils.format(modificationDate, DateUtils.FORMAT_TIME_HMS);
	fileXml.addAttribute("modificationTime", time);

	return fileXml;
}
 
Example 3
Source File: SmbTvShow.java    From Mizuu with Apache License 2.0 6 votes vote down vote up
@Override
public void addToResults(SmbFile file, TreeSet<String> results) {
    if (MizLib.checkFileTypes(file.getCanonicalPath())) {
        try {
            if (file.length() < getFileSizeLimit())
                return;
        } catch (SmbException e) {
            return;
        }

        if (!clearLibrary())
            if (existingEpisodes.get(file.getCanonicalPath()) != null) return;

        //Add the file if it reaches this point
        results.add(file.getCanonicalPath());
    }
}
 
Example 4
Source File: SmbMovie.java    From Mizuu with Apache License 2.0 6 votes vote down vote up
@Override
public void addToResults(SmbFile file, TreeSet<String> results) {
	if (MizLib.checkFileTypes(file.getCanonicalPath())) {
		try {
			if (file.length() < getFileSizeLimit() && !file.getName().equalsIgnoreCase("video_ts.ifo"))
				return;
		} catch (SmbException e) {
			return;
		}

		if (!clearLibrary())
			if (existingMovies.get(file.getCanonicalPath()) != null) return;

		String tempFileName = file.getName().substring(0, file.getName().lastIndexOf("."));
		if (tempFileName.toLowerCase(Locale.ENGLISH).matches(".*part[2-9]|cd[2-9]")) return;

		//Add the file if it reaches this point
		results.add(file.getCanonicalPath());
	}
}
 
Example 5
Source File: Futils.java    From PowerFileExplorer with GNU General Public License v3.0 5 votes vote down vote up
public static long folderSize(SmbFile directory) {
    long length = 0;
    try {
        for (SmbFile file:directory.listFiles()) {

            if (file.isFile())
                length += file.length();
            else
                length += folderSize(file);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return length;
}
 
Example 6
Source File: NetworkExplorer.java    From jcifs with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected int compareSizes ( SmbFile f1, String f1name, SmbFile f2 ) throws IOException {
    long diff;

    if ( f1.isDirectory() != f2.isDirectory() ) {
        return f1.isDirectory() ? -1 : 1;
    }
    if ( f1.isDirectory() ) {
        return f1name.compareToIgnoreCase(f2.getName());
    }
    diff = f1.length() - f2.length();
    if ( diff == 0 ) {
        return f1name.compareToIgnoreCase(f2.getName());
    }
    return diff > 0 ? -1 : 1;
}
 
Example 7
Source File: NetworkExplorer.java    From jcifs-ng with GNU Lesser General Public License v2.1 5 votes vote down vote up
protected int compareSizes ( SmbFile f1, String f1name, SmbFile f2 ) throws IOException {
    long diff;

    if ( f1.isDirectory() != f2.isDirectory() ) {
        return f1.isDirectory() ? -1 : 1;
    }
    if ( f1.isDirectory() ) {
        return f1name.compareToIgnoreCase(f2.getName());
    }
    diff = f1.length() - f2.length();
    if ( diff == 0 ) {
        return f1name.compareToIgnoreCase(f2.getName());
    }
    return diff > 0 ? -1 : 1;
}
 
Example 8
Source File: StreamSource.java    From Amphitheatre with Apache License 2.0 5 votes vote down vote up
public StreamSource(SmbFile file) throws SmbException{
	fp = 0;
	len = file.length();
	mime = VideoUtils.getMimeType(file.getName(), false);
	name = file.getName();
	this.file = file;
	bufferSize = 1024*32;
}
 
Example 9
Source File: Samba1FileSystem.java    From iaf with Apache License 2.0 5 votes vote down vote up
@Override
public long getFileSize(SmbFile f) throws FileSystemException {
	try {
		return f.length();
	} catch (SmbException e) {
		throw new FileSystemException(e);
	}
}
 
Example 10
Source File: StreamSource.java    From Mizuu with Apache License 2.0 5 votes vote down vote up
public StreamSource(SmbFile file) throws SmbException{
	fp = 0;
	len = file.length();
	mime = "video/*";
	name = file.getName();
	this.file = file;
	bufferSize = 16 * 1024;
}
 
Example 11
Source File: HFile.java    From PowerFileExplorer with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Helper method to find length
 * @param context
 * @return
 */
public long length(Context context) {

    long s = 0l;
    switch (mode) {
        case SMB:
            SmbFile smbFile=getSmbFile();
            if (smbFile != null)
                try {
                    s = smbFile.length();
                } catch (SmbException e) {
                }
            return s;
        case FILE:
            s = new File(path).length();
            return s;
        case ROOT:
            BaseFile baseFile=generateBaseFileFromParent();
            if (baseFile != null) return baseFile.size;
            break;
        case OTG:
            s = OTGUtil.getDocumentFile(path, context, false).length();
            break;
        case DROPBOX:
            s = dataUtils.getAccount(OpenMode.DROPBOX)
	.getMetadata(CloudUtil.stripPath(OpenMode.DROPBOX, path)).getSize();
            break;
        case BOX:
            s = dataUtils.getAccount(OpenMode.BOX)
	.getMetadata(CloudUtil.stripPath(OpenMode.BOX, path)).getSize();
            break;
        case ONEDRIVE:
            s = dataUtils.getAccount(OpenMode.ONEDRIVE)
	.getMetadata(CloudUtil.stripPath(OpenMode.ONEDRIVE, path)).getSize();
            break;
        case GDRIVE:
            s = dataUtils.getAccount(OpenMode.GDRIVE)
	.getMetadata(CloudUtil.stripPath(OpenMode.GDRIVE, path)).getSize();
            break;
        default:
            break;
    }
    return s;
}