?? wilson.txt
字號(hào):
implements Enumeration
{
public static final int RECLS_F_FILES = 0x00000001;
public static final int RECLS_F_DIRECTORIES = 0x00000002;
public static final int RECLS_F_LINKS = 0x00000004;
public static final int RECLS_F_DEVICES = 0x00000008;
public static final int RECLS_F_RECURSIVE = 0x00010000;
public static final int RECLS_F_NO_FOLLOW_LINKS = 0x00020000;
public static final int RECLS_F_DIRECTORY_PARTS = 0x00040000;
public static final int RECLS_F_DETAILS_LATER = 0x00080000;
private Search(String searchRoot, String pattern, int flags)
{
// Ctors cannot be native
m_hSearch = Initialise(searchRoot, pattern, flags);
}
public native void Close();
public void Finalize()
{
Close();
}
public static Search MakeSearch(String searchRoot, String pattern,
int flags) throws ReclsException
{
return new Search(searchRoot, pattern, flags);
}
public final native boolean hasMoreElements();
public final native Object nextElement();
/// Native method implementations
private native int Initialise(String searchRoot,String pattern,int flags);
// Implementation
static
{
System.loadLibrary("recls_jni");
}
/// Members
private int m_hSearch;
private int m_rc;
}
Listing 5:
/* /////////////////////////////////////////////////////////////
* Extract from recls_Search.cpp
* www: www.synesis.com.au/software
* Copyright (C) 2002, Synesis Software Pty Ltd.
* (Licensed under the Synesis Software Standard Source License:
* http://www.synesis.com.au/licenses/ssssl.html)
* ////////////////////////////////////////////////////////// */
const char CLSNM_ENTRY[] = "Lorg/recls/Entry;";
const char CLSNM_STRING[] = "Ljava/lang/String;";
const char CLSNM_NOSUCHELEMENTX[] = "Ljava/lang/NoSuchElementException;";
const char CLSNM_ILLEGALSTATEX[] = "Ljava/lang/IllegalStateException;";
const char FIELDNAME_HSRCH[] = "m_hSearch";
jfieldID GetSearchFieldID(JNIEnv *henv, jobject obj)
{
jclass clsEntry = henv->GetObjectClass(obj);
jfieldID fid = henv->GetFieldID(clsEntry, FIELDNAME_HSRCH, "I");
return fid;
}
hrecls_t SearchFromJObject(JNIEnv *henv, jobject obj)
{
jfieldID fid = GetSearchFieldID(henv, obj);
return reinterpret_cast<hrecls_t>(henv->GetIntField(obj, fid));
}
void ThrowException(JNIEnv *henv, char const *className, char const *message)
{
va_list args;
va_start(args, message);
jclass clsX = henv->FindClass(className);
if(NULL != clsX)
{
henv->ThrowNew(clsX, message);
henv->DeleteLocalRef(clsX);
}
va_end(args);
}
jstring StringFromRange(JNIEnv *henv, recls_char_t const *from,
recls_char_t const *to)
{
typedef stlsoft::auto_buffer<recls_char_t
, stlsoft::malloc_allocator<recls_char_t>
, RECLS_PATH_MAX
> buffer_t;
buffer_t buffer(1 + (to - from));
#ifdef RECLS_CHAR_TYPE_IS_CHAR
strncpy(buffer, from, buffer.size() - 1);
buffer[buffer.size() - 1] = 0;
return henv->NewStringUTF(buffer);
#elif defined(RECLS_CHAR_TYPE_IS_WCHAR
wcsncpy(buffer, from, buffer.size() - 1);
buffer[buffer.size() - 1] = 0;
return henv->NewString(buffer);
#else /* ?char type */
# error recls char type must be discriminated
#endif /* char type */
}
JNIEXPORT jobject JNICALL Java_org_recls_Search_nextElement
(JNIEnv *henv, jobject obj)
{
hrecls_t hSrch = SearchFromJObject(henv, obj);
recls_rc_t rc;
jobject entry;
if( NULL == hSrch ||
RECLS_FAILED(rc = Recls_GetLastError(hSrch)))
{
ThrowException(henv, CLSNM_NOSUCHELEMENTX, "No more elements in search");
entry = NULL;
}
else
{
recls_info_t hEntry;
// (i) Get the details of the current position ...
rc = Recls_GetDetails(hSrch, &hEntry);
if(RECLS_SUCCEEDED(rc))
{
jclass clsEntry = henv->FindClass(CLSNM_ENTRY);
jmethodID midEntryCtor = henv->GetMethodID(clsEntry, "<init>",
"(ILjava/lang/String;[Ljava/lang/String;)V");
size_t cDirParts = Recls_GetDirectoryPartProperty(hEntry,
-1, NULL, 0);
jstring path = StringFromRange(henv, hEntry->path.begin,
hEntry->path.end);
jclass clsString = henv->FindClass(CLSNM_STRING);
jobjectArray dirParts = henv->NewObjectArray(cDirParts,
clsString, NULL);
for(size_t i = 0; i < cDirParts; ++i)
{
recls_strptrs_t const *part = hEntry->directoryParts.begin + i;
jstring dirPart = StringFromRange(henv, part->begin, part->end);
henv->SetObjectArrayElement(dirParts, i, dirPart);
}
entry = henv->NewObject(clsEntry, midEntryCtor, hEntry, path, dirParts);
// (ii) ... and then advance to the next
rc = Recls_GetNext(hSrch);
if(RECLS_FAILED(rc))
{
jfieldID fid = GetSearchFieldID(henv, obj);
henv->SetIntField(obj, fid, 0);
Recls_SearchClose(hSrch);
}
}
else
{
ThrowException(henv,CLSNM_ILLEGALSTATEX,"Search entry retrieval failed");
}
}
return entry;
}
Listing 6:
/* /////////////////////////////////////////////////////////////
* Extract from org/recls/Search.java
* www: http://www.recls.org/
* Copyright (C) 2002, Synesis Software Pty Ltd.
* (Licensed under the Synesis Software Standard Source License:
* http://www.synesis.com.au/licenses/ssssl.html)
* ////////////////////////////////////////////////////////// */
package org.recls;
import java.util.Date;
public class Entry
{
private Entry(int hEntry, String path, String[] directoryParts)
{
m_hEntry = hEntry;
m_path = path;
m_directoryParts = directoryParts;
}
public native void Close();
public void Finalize()
{
Close();
}
// Properties
public String getPath()
{
return m_path;
}
public native char getDrive();
public native String getDirectory();
public native String getDirectoryPath();
public String[] getDirectoryParts()
{
return m_directoryParts;
}
public native String getFile();
public native String getShortFile();
public native String getFileName();
public native String getFileExt();
public Date getCreationTime()
{
return new Date(getCreationTime_());
}
public Date getModificationTime()
{
return new Date(getModificationTime_());
}
public Date getLastAccessTime()
{
return new Date(getLastAccessTime_());
}
public Date getLastStatusChangeTime()
{
return new Date(getLastStatusChangeTime_());
}
public native long getSize();
public native boolean isReadOnly();
public native boolean isDirectory();
public native boolean isLink();
public String toString()
{
return m_path;
}
// Implementation methods
public native long getCreationTime_();
public native long getModificationTime_();
public native long getLastAccessTime_();
public native long getLastStatusChangeTime_();
// Members
private int m_hEntry; // The opaque handle to the entry
private String m_path;
private String[] m_directoryParts;
}
Listing 7:
/* /////////////////////////////////////////////////////////////
* Extract from org/recls/Search.java
* www: http://www.recls.org/
* Copyright (C) 2002, Synesis Software Pty Ltd.
* (Licensed under the Synesis Software Standard Source License:
* http://www.synesis.com.au/licenses/ssssl.html)
* ////////////////////////////////////////////////////////// */
import org.recls.Entry;
import org.recls.ReclsException;
import org.recls.Search;
import java.util.Enumeration;
public class recls_test
{
public static void main(String[] args)
{
. . . // deduce dir, pattern and flags
try
{
Search search = Search.MakeSearch(rootDir, pattern, flags);
for(Enumeration en = search; en.hasMoreElements(); ++total)
{
Object el = en.nextElement();
System.out.println(el);
if(!bSuccinct)
{
Entry entry = (Entry)el;
System.out.println(" Path: " + entry.getPath());
System.out.println(" Drive: " + entry.getDrive());
System.out.println(" Directory: " + entry.getDirectory());
System.out.println(" DirectoryPath: " + entry.getDirectoryPath());
if((flags & Search.RECLS_F_DIRECTORY_PARTS) ==
Search.RECLS_F_DIRECTORY_PARTS)
{
String[] dirParts = entry.getDirectoryParts();
for(int j = 0; j < dirParts.length; ++j)
{
System.out.println(" " + dirParts[j]);
}
}
System.out.println(" File: " + entry.getFile());
System.out.println(" ShortFile: " + entry.getShortFile());
System.out.println(" FileName: " + entry.getFileName());
System.out.println(" FileExtL " + entry.getFileExt());
System.out.println(" Size: " + entry.getSize());
System.out.println(" CreationTime: " + entry.getCreationTime());
System.out.println(" ModificationTime: " + entry.getModificationTime());
System.out.println(" LastAccessTime: " + entry.getLastAccessTime());
System.out.println(" LastStatusChangeTime: " + entry.getLastStatusChangeTime());
System.out.println(" isReadOnly: " + entry.isReadOnly());
System.out.println(" isDirectory: " + entry.isDirectory());
System.out.println(" isLink: " + entry.isLink());
}
}
search.Close();
System.out.println(" Total matched: " + total);
}
catch(ReclsException x)
{
System.out.println(x);
}
}
}
1
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -