├── .gitignore ├── README.md ├── VDiskSdk ├── .project ├── AndroidManifest.xml ├── libs │ └── json_simple-1.1.jar ├── lint.xml ├── proguard-project.txt ├── project.properties ├── res │ ├── drawable-hdpi │ │ ├── dialog_bg.9.png │ │ └── ic_launcher.png │ ├── drawable-ldpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── style.xml └── src │ └── com │ └── vdisk │ ├── android │ ├── ComplexUploadHandler.java │ ├── VDiskAuthSession.java │ ├── VDiskDB.java │ ├── VDiskDialog.java │ └── VDiskDialogListener.java │ ├── net │ ├── ComplexUploadInputStreamEntity.java │ ├── ProgressListener.java │ ├── RESTUtility.java │ ├── SdkVersion.java │ ├── SimpleUploadInputStreamEntity.java │ ├── VDiskAPI.java │ ├── exception │ │ ├── VDiskDialogError.java │ │ ├── VDiskDownloadFileExistException.java │ │ ├── VDiskException.java │ │ ├── VDiskFileNotFoundException.java │ │ ├── VDiskFileSizeException.java │ │ ├── VDiskIOException.java │ │ ├── VDiskLocalStorageFullException.java │ │ ├── VDiskParseException.java │ │ ├── VDiskPartialFileException.java │ │ ├── VDiskSSLException.java │ │ ├── VDiskServerException.java │ │ └── VDiskUnlinkedException.java │ ├── jsonextract │ │ ├── JsonBase.java │ │ ├── JsonExtractionException.java │ │ ├── JsonExtractor.java │ │ ├── JsonList.java │ │ ├── JsonMap.java │ │ └── JsonThing.java │ └── session │ │ ├── AbstractSession.java │ │ ├── AccessToken.java │ │ ├── AppKeyPair.java │ │ ├── RetryHandler.java │ │ ├── Session.java │ │ ├── Token.java │ │ └── WeiboAccessToken.java │ └── utils │ ├── BASE64Encoder.java │ ├── Config.java │ ├── DesEncrypt.java │ ├── Digest.java │ ├── Logger.java │ └── Signature.java ├── VDiskSdk_Example ├── .project ├── AndroidManifest.xml ├── libs │ ├── json_simple-1.1.jar │ └── weibosdkcore.jar ├── proguard-project.txt ├── project.properties ├── res │ ├── drawable-hdpi │ │ ├── ic_launcher.png │ │ └── icon.png │ ├── drawable-ldpi │ │ └── ic_launcher.png │ ├── drawable-mdpi │ │ └── ic_launcher.png │ ├── drawable-xhdpi │ │ └── ic_launcher.png │ ├── layout │ │ ├── auth_main.xml │ │ ├── function_item.xml │ │ ├── input_dialog.xml │ │ ├── test_result.xml │ │ ├── thumb_dialog.xml │ │ └── vdisk_test.xml │ ├── values-en-rUS │ │ └── strings.xml │ └── values │ │ └── strings.xml └── src │ └── com │ ├── sina │ └── weibo │ │ └── sdk │ │ └── demo │ │ ├── AccessTokenKeeper.java │ │ └── Constants.java │ └── vdisk │ └── android │ └── example │ ├── DownloadFile.java │ ├── LargeFileUpload.java │ ├── OAuthActivity.java │ ├── UploadPicture.java │ ├── VDiskResultActivity.java │ └── VDiskTestActivity.java ├── doc ├── allclasses-frame.html ├── allclasses-noframe.html ├── com │ └── vdisk │ │ ├── android │ │ ├── ComplexUploadHandler.ComplexUploadStatus.html │ │ ├── ComplexUploadHandler.html │ │ ├── VDiskAuthSession.html │ │ ├── VDiskDB.html │ │ ├── VDiskDialog.WeiboWebViewClient.html │ │ ├── VDiskDialog.html │ │ ├── VDiskDialogListener.html │ │ ├── class-use │ │ │ ├── ComplexUploadHandler.ComplexUploadStatus.html │ │ │ ├── ComplexUploadHandler.html │ │ │ ├── VDiskAuthSession.html │ │ │ ├── VDiskDB.html │ │ │ ├── VDiskDialog.WeiboWebViewClient.html │ │ │ ├── VDiskDialog.html │ │ │ └── VDiskDialogListener.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html │ │ ├── net │ │ ├── ComplexUploadInputStreamEntity.html │ │ ├── ProgressListener.ProgressHttpEntity.CountingOutputStream.html │ │ ├── ProgressListener.ProgressHttpEntity.html │ │ ├── ProgressListener.html │ │ ├── RESTUtility.RequestMethod.html │ │ ├── RESTUtility.html │ │ ├── SdkVersion.html │ │ ├── SimpleUploadInputStreamEntity.html │ │ ├── VDiskAPI.Account.html │ │ ├── VDiskAPI.AlbumPage.html │ │ ├── VDiskAPI.BasicUploadRequest.html │ │ ├── VDiskAPI.ComplexUploadRequest.html │ │ ├── VDiskAPI.CreatedCopyRef.html │ │ ├── VDiskAPI.DeltaEntry.JsonExtractor.html │ │ ├── VDiskAPI.DeltaEntry.html │ │ ├── VDiskAPI.DeltaPage.html │ │ ├── VDiskAPI.Entry.html │ │ ├── VDiskAPI.RequestAndResponse.html │ │ ├── VDiskAPI.ThumbSize.html │ │ ├── VDiskAPI.UploadRequest.html │ │ ├── VDiskAPI.VDiskFileInfo.html │ │ ├── VDiskAPI.VDiskInputStream.html │ │ ├── VDiskAPI.VDiskLink.html │ │ ├── VDiskAPI.VDiskUploadFileInfo.html │ │ ├── VDiskAPI.html │ │ ├── class-use │ │ │ ├── ComplexUploadInputStreamEntity.html │ │ │ ├── ProgressListener.ProgressHttpEntity.CountingOutputStream.html │ │ │ ├── ProgressListener.ProgressHttpEntity.html │ │ │ ├── ProgressListener.html │ │ │ ├── RESTUtility.RequestMethod.html │ │ │ ├── RESTUtility.html │ │ │ ├── SdkVersion.html │ │ │ ├── SimpleUploadInputStreamEntity.html │ │ │ ├── VDiskAPI.Account.html │ │ │ ├── VDiskAPI.AlbumPage.html │ │ │ ├── VDiskAPI.BasicUploadRequest.html │ │ │ ├── VDiskAPI.ComplexUploadRequest.html │ │ │ ├── VDiskAPI.CreatedCopyRef.html │ │ │ ├── VDiskAPI.DeltaEntry.JsonExtractor.html │ │ │ ├── VDiskAPI.DeltaEntry.html │ │ │ ├── VDiskAPI.DeltaPage.html │ │ │ ├── VDiskAPI.Entry.html │ │ │ ├── VDiskAPI.RequestAndResponse.html │ │ │ ├── VDiskAPI.ThumbSize.html │ │ │ ├── VDiskAPI.UploadRequest.html │ │ │ ├── VDiskAPI.VDiskFileInfo.html │ │ │ ├── VDiskAPI.VDiskInputStream.html │ │ │ ├── VDiskAPI.VDiskLink.html │ │ │ ├── VDiskAPI.VDiskUploadFileInfo.html │ │ │ └── VDiskAPI.html │ │ ├── exception │ │ │ ├── VDiskDialogError.html │ │ │ ├── VDiskDownloadFileExistException.html │ │ │ ├── VDiskException.html │ │ │ ├── VDiskFileNotFoundException.html │ │ │ ├── VDiskFileSizeException.html │ │ │ ├── VDiskIOException.html │ │ │ ├── VDiskLocalStorageFullException.html │ │ │ ├── VDiskParseException.html │ │ │ ├── VDiskPartialFileException.html │ │ │ ├── VDiskSSLException.html │ │ │ ├── VDiskServerException.Error.html │ │ │ ├── VDiskServerException.html │ │ │ ├── VDiskUnlinkedException.html │ │ │ ├── class-use │ │ │ │ ├── VDiskDialogError.html │ │ │ │ ├── VDiskDownloadFileExistException.html │ │ │ │ ├── VDiskException.html │ │ │ │ ├── VDiskFileNotFoundException.html │ │ │ │ ├── VDiskFileSizeException.html │ │ │ │ ├── VDiskIOException.html │ │ │ │ ├── VDiskLocalStorageFullException.html │ │ │ │ ├── VDiskParseException.html │ │ │ │ ├── VDiskPartialFileException.html │ │ │ │ ├── VDiskSSLException.html │ │ │ │ ├── VDiskServerException.Error.html │ │ │ │ ├── VDiskServerException.html │ │ │ │ └── VDiskUnlinkedException.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ ├── package-tree.html │ │ │ └── package-use.html │ │ ├── jsonextract │ │ │ ├── JsonBase.html │ │ │ ├── JsonExtractionException.html │ │ │ ├── JsonExtractor.html │ │ │ ├── JsonList.Extractor.html │ │ │ ├── JsonList.WrapperIterator.html │ │ │ ├── JsonList.html │ │ │ ├── JsonMap.WrappedEntry.html │ │ │ ├── JsonMap.WrapperIterator.html │ │ │ ├── JsonMap.html │ │ │ ├── JsonThing.OptionalExtractor.html │ │ │ ├── JsonThing.html │ │ │ ├── class-use │ │ │ │ ├── JsonBase.html │ │ │ │ ├── JsonExtractionException.html │ │ │ │ ├── JsonExtractor.html │ │ │ │ ├── JsonList.Extractor.html │ │ │ │ ├── JsonList.WrapperIterator.html │ │ │ │ ├── JsonList.html │ │ │ │ ├── JsonMap.WrappedEntry.html │ │ │ │ ├── JsonMap.WrapperIterator.html │ │ │ │ ├── JsonMap.html │ │ │ │ ├── JsonThing.OptionalExtractor.html │ │ │ │ └── JsonThing.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ ├── package-tree.html │ │ │ └── package-use.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ ├── package-use.html │ │ └── session │ │ │ ├── AbstractSession.DBClientConnManager.html │ │ │ ├── AbstractSession.DBConnectionReuseStrategy.html │ │ │ ├── AbstractSession.DBKeepAliveStrategy.html │ │ │ ├── AbstractSession.GzipDecompressingEntity.html │ │ │ ├── AbstractSession.IdleConnectionCloserThread.html │ │ │ ├── AbstractSession.TrustAllManager.html │ │ │ ├── AbstractSession.TrustAllSSLSocketFactory.html │ │ │ ├── AbstractSession.html │ │ │ ├── AccessToken.html │ │ │ ├── AppKeyPair.html │ │ │ ├── RetryHandler.html │ │ │ ├── Session.AccessType.html │ │ │ ├── Session.ProxyInfo.html │ │ │ ├── Session.html │ │ │ ├── Token.html │ │ │ ├── WeiboAccessToken.html │ │ │ ├── class-use │ │ │ ├── AbstractSession.DBClientConnManager.html │ │ │ ├── AbstractSession.DBConnectionReuseStrategy.html │ │ │ ├── AbstractSession.DBKeepAliveStrategy.html │ │ │ ├── AbstractSession.GzipDecompressingEntity.html │ │ │ ├── AbstractSession.IdleConnectionCloserThread.html │ │ │ ├── AbstractSession.TrustAllManager.html │ │ │ ├── AbstractSession.TrustAllSSLSocketFactory.html │ │ │ ├── AbstractSession.html │ │ │ ├── AccessToken.html │ │ │ ├── AppKeyPair.html │ │ │ ├── RetryHandler.html │ │ │ ├── Session.AccessType.html │ │ │ ├── Session.ProxyInfo.html │ │ │ ├── Session.html │ │ │ ├── Token.html │ │ │ └── WeiboAccessToken.html │ │ │ ├── package-frame.html │ │ │ ├── package-summary.html │ │ │ ├── package-tree.html │ │ │ └── package-use.html │ │ └── utils │ │ ├── BASE64Encoder.html │ │ ├── Config.html │ │ ├── DesEncrypt.html │ │ ├── Digest.html │ │ ├── Logger.NetworkState.html │ │ ├── Logger.html │ │ ├── Signature.html │ │ ├── class-use │ │ ├── BASE64Encoder.html │ │ ├── Config.html │ │ ├── DesEncrypt.html │ │ ├── Digest.html │ │ ├── Logger.NetworkState.html │ │ ├── Logger.html │ │ └── Signature.html │ │ ├── package-frame.html │ │ ├── package-summary.html │ │ ├── package-tree.html │ │ └── package-use.html ├── constant-values.html ├── deprecated-list.html ├── help-doc.html ├── index-files │ ├── index-1.html │ ├── index-10.html │ ├── index-11.html │ ├── index-12.html │ ├── index-13.html │ ├── index-14.html │ ├── index-15.html │ ├── index-16.html │ ├── index-17.html │ ├── index-18.html │ ├── index-19.html │ ├── index-2.html │ ├── index-20.html │ ├── index-21.html │ ├── index-22.html │ ├── index-23.html │ ├── index-24.html │ ├── index-3.html │ ├── index-4.html │ ├── index-5.html │ ├── index-6.html │ ├── index-7.html │ ├── index-8.html │ └── index-9.html ├── index.html ├── overview-frame.html ├── overview-summary.html ├── overview-tree.html ├── package-list ├── resources │ ├── background.gif │ ├── tab.gif │ ├── titlebar.gif │ └── titlebar_end.gif ├── serialized-form.html └── stylesheet.css └── 微盘AndroidSDK开发者文档.pdf /.gitignore: -------------------------------------------------------------------------------- 1 | # built application files 2 | *.apk 3 | *.ap_ 4 | 5 | # files for the dex VM 6 | *.dex 7 | 8 | # Java class files 9 | *.class 10 | 11 | # generated files 12 | bin/ 13 | gen/ 14 | R.java 15 | 16 | # Local configuration file (sdk path, etc) 17 | local.properties 18 | 19 | # Eclipse project files 20 | #.classpath 21 | #.project 22 | .settings/ 23 | 24 | 25 | # Mac OS X Finder and whatnot 26 | .DS_Store 27 | 28 | # XCode (and ancestors) per-user config (very noisy, and not relevant) 29 | *.mode1 30 | *.mode1v3 31 | *.mode2v3 32 | *.perspective 33 | *.perspectivev3 34 | *.pbxuser 35 | xcuserdata 36 | *.xcworkspace 37 | 38 | # Generated files 39 | VersionX-revision.h 40 | 41 | 42 | # build products 43 | build/ 44 | *.[oa] 45 | 46 | # Other source repository archive directories (protects when importing) 47 | .hg 48 | .svn 49 | CVS 50 | *.DS_Store 51 | 52 | VDiskSdk_Example/.classpath 53 | 54 | VDiskSdk/.classpath 55 | 56 | *.gradle 57 | 58 | *.iml 59 | 60 | *.xml 61 | 62 | VDiskSdk/.classpath 63 | 64 | VDiskSdk_Example/.classpath 65 | 66 | *.zip 67 | 68 | .idea/.name 69 | 70 | VDiskSdk/.classpath 71 | 72 | VDiskSdk_Example/.classpath 73 | 74 | VDiskSdk_Example/.classpath 75 | -------------------------------------------------------------------------------- /VDiskSdk/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | VDiskSdk 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /VDiskSdk/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /VDiskSdk/libs/json_simple-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CloudSide/VdiskSDK-Android/4bd9d5a1aa9d6f398e81e0b58250e5e93cf641af/VDiskSdk/libs/json_simple-1.1.jar -------------------------------------------------------------------------------- /VDiskSdk/lint.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /VDiskSdk/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /VDiskSdk/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}\tools\proguard\proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-14 15 | android.library=true 16 | -------------------------------------------------------------------------------- /VDiskSdk/res/drawable-hdpi/dialog_bg.9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CloudSide/VdiskSDK-Android/4bd9d5a1aa9d6f398e81e0b58250e5e93cf641af/VDiskSdk/res/drawable-hdpi/dialog_bg.9.png -------------------------------------------------------------------------------- /VDiskSdk/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CloudSide/VdiskSDK-Android/4bd9d5a1aa9d6f398e81e0b58250e5e93cf641af/VDiskSdk/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /VDiskSdk/res/drawable-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CloudSide/VdiskSDK-Android/4bd9d5a1aa9d6f398e81e0b58250e5e93cf641af/VDiskSdk/res/drawable-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /VDiskSdk/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CloudSide/VdiskSDK-Android/4bd9d5a1aa9d6f398e81e0b58250e5e93cf641af/VDiskSdk/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /VDiskSdk/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CloudSide/VdiskSDK-Android/4bd9d5a1aa9d6f398e81e0b58250e5e93cf641af/VDiskSdk/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /VDiskSdk/res/values/colors.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | #ff000000 5 | #ffffffff 6 | #00000000 7 | #4A4D4A 8 | -------------------------------------------------------------------------------- /VDiskSdk/res/values/dimens.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 3dp 4 | 30dp 5 | 3dp 6 | 10dp 7 | 10dp 8 | 10dp 9 | 5dp 10 | 30dp 11 | 12 | -------------------------------------------------------------------------------- /VDiskSdk/res/values/strings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 微盘Sdk 5 | 6 | DefaultLocale 7 | 8 | -------------------------------------------------------------------------------- /VDiskSdk/res/values/style.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 13 | 14 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/android/VDiskDB.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.android; 2 | 3 | import android.content.ContentValues; 4 | import android.content.Context; 5 | import android.database.Cursor; 6 | import android.database.sqlite.SQLiteDatabase; 7 | import android.database.sqlite.SQLiteOpenHelper; 8 | 9 | /** 10 | * 此数据库表中有两个字段,file_id 和 file_obj. file_id = MD5(上传文件本地路径 11 | * +上传文件的微盘目标路径),用来标识待上传的文件; file_obj表示文件对象序列化后的形式 12 | * 13 | * There are two columns in this table in database: file_id & file_obj. file_id 14 | * = MD5(Local path of file to upload + target VDisk path of file to upload), to 15 | * identify the file to upload; file_obj, the form of serialized file object. 16 | * 17 | * @author Kevin 18 | * 19 | */ 20 | public class VDiskDB extends SQLiteOpenHelper { 21 | 22 | @SuppressWarnings("unused") 23 | private static Context sContext; 24 | 25 | private final static String DB_NAME = "vdiskdb"; 26 | 27 | private final static int VERSION = 1; 28 | 29 | private static VDiskDB instance = null; 30 | 31 | private SQLiteDatabase db = null; 32 | 33 | private final String UPLOAD_TABLE = "vdisk_upload"; 34 | private final String UPLOAD_FILE_ID = "file_id"; 35 | private final String UPLOAD_FILE_OBJECT = "file_obj"; 36 | 37 | @SuppressWarnings("static-access") 38 | private VDiskDB(Context context) { 39 | super(context, DB_NAME, null, VERSION); 40 | this.sContext = context; 41 | 42 | try { 43 | db = this.getWritableDatabase(); 44 | } catch (Exception e) { 45 | e.printStackTrace(); 46 | } 47 | } 48 | 49 | public static VDiskDB getInstance(Context ctx) { 50 | if (instance == null) { 51 | return instance = new VDiskDB(ctx); 52 | } 53 | return instance; 54 | } 55 | 56 | @Override 57 | public void onCreate(SQLiteDatabase db) { 58 | String sql = "CREATE TABLE IF NOT EXISTS " + UPLOAD_TABLE + " (" 59 | + "_id" + " Integer primary key autoincrement, " 60 | + UPLOAD_FILE_ID + " TEXT UNIQUE, " + UPLOAD_FILE_OBJECT 61 | + " TEXT )"; 62 | db.execSQL(sql); 63 | } 64 | 65 | @Override 66 | public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { 67 | String sql = "DROP TABLE IF EXISTS " + UPLOAD_TABLE; 68 | db.execSQL(sql); 69 | onCreate(db); 70 | } 71 | 72 | /** 73 | * 更新上传文件分段信息 74 | * 75 | * Update segment information of upload file. 76 | * 77 | * @param fileId 78 | * @param serStr 79 | * @return 80 | */ 81 | public boolean updateUploadFileInfo(String fileId, String serStr) { 82 | if (readUploadFileInfo(fileId) == null) { 83 | ContentValues c = new ContentValues(); 84 | c.put(UPLOAD_FILE_ID, fileId); 85 | c.put(UPLOAD_FILE_OBJECT, serStr); 86 | 87 | long rownum = db.insert(UPLOAD_TABLE, null, c); 88 | if (rownum == -1) { 89 | return false; 90 | } 91 | 92 | return true; 93 | } else { 94 | ContentValues c = new ContentValues(); 95 | c.put(UPLOAD_FILE_OBJECT, serStr); 96 | 97 | db.update(UPLOAD_TABLE, c, UPLOAD_FILE_ID + " =? ", 98 | new String[] { fileId }); 99 | return true; 100 | } 101 | } 102 | 103 | /** 104 | * 删除上传文件分段信息 105 | * 106 | * Delete segment information of upload file. 107 | * 108 | * @param fileId 109 | */ 110 | public void deleteUploadFileInfo(String fileId) { 111 | String sql = "DELETE FROM " + UPLOAD_TABLE + " WHERE " + UPLOAD_FILE_ID 112 | + " = ?"; 113 | 114 | String[] args = new String[] { fileId }; 115 | 116 | db.execSQL(sql, args); 117 | } 118 | 119 | /** 120 | * 读取上传文件分段信息 121 | * 122 | * Read segment information of upload file. 123 | * 124 | * @param fileId 125 | * @return 126 | */ 127 | public String readUploadFileInfo(String fileId) { 128 | Cursor cursor = db.query(UPLOAD_TABLE, 129 | new String[] { UPLOAD_FILE_OBJECT }, UPLOAD_FILE_ID + " = ?", 130 | new String[] { fileId }, null, null, null); 131 | 132 | if (cursor != null) { 133 | if (cursor.moveToFirst()) { 134 | String serStr = cursor.getString(0); 135 | cursor.close(); 136 | return serStr; 137 | } 138 | 139 | cursor.close(); 140 | } 141 | 142 | return null; 143 | } 144 | 145 | } 146 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/android/VDiskDialogListener.java: -------------------------------------------------------------------------------- 1 | 2 | package com.vdisk.android; 3 | 4 | import android.os.Bundle; 5 | 6 | import com.vdisk.net.exception.VDiskDialogError; 7 | import com.vdisk.net.exception.VDiskException; 8 | 9 | public interface VDiskDialogListener { 10 | 11 | public void onComplete(Bundle values); 12 | 13 | public void onError(VDiskDialogError error); 14 | 15 | public void onVDiskException(VDiskException exception); 16 | 17 | public void onCancel(); 18 | 19 | } 20 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/ComplexUploadInputStreamEntity.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.net; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.io.OutputStream; 6 | import java.io.RandomAccessFile; 7 | import java.util.concurrent.Callable; 8 | import java.util.concurrent.ExecutorService; 9 | import java.util.concurrent.Executors; 10 | import java.util.concurrent.Future; 11 | import java.util.concurrent.TimeUnit; 12 | import java.util.concurrent.TimeoutException; 13 | 14 | import org.apache.http.entity.AbstractHttpEntity; 15 | 16 | import android.util.Log; 17 | 18 | /** 19 | * 对上传文件流的封装。实现了对大文件的分段控制。 20 | * 21 | * Encapsulation of upload input stream. To do the segmented control of big 22 | * files. 23 | * 24 | * @author Kevin 25 | * 26 | */ 27 | public class ComplexUploadInputStreamEntity extends AbstractHttpEntity { 28 | 29 | private final static int BUFFER_SIZE = 8192; 30 | 31 | private long length; 32 | private long startPos; 33 | private boolean consumed = false; 34 | RandomAccessFile randomAccessFile = null; 35 | 36 | public ComplexUploadInputStreamEntity(String srcPath, long startPos, 37 | long length) throws IOException { 38 | super(); 39 | 40 | this.length = length; 41 | this.startPos = startPos; 42 | randomAccessFile = new RandomAccessFile(srcPath, "rw"); 43 | randomAccessFile.seek(startPos); 44 | } 45 | 46 | public boolean isRepeatable() { 47 | return false; 48 | } 49 | 50 | public long getContentLength() { 51 | return this.length; 52 | } 53 | 54 | public long getStartPosition() { 55 | return startPos; 56 | } 57 | 58 | public InputStream getContent() throws IOException { 59 | return null; 60 | } 61 | 62 | public void writeTo(final OutputStream outstream) throws IOException { 63 | if (outstream == null) { 64 | throw new IllegalArgumentException("Output stream may not be null"); 65 | } 66 | 67 | byte[] buffer = new byte[BUFFER_SIZE]; 68 | int read; 69 | long count = 0; 70 | 71 | while (true) { 72 | read = randomAccessFile.read(buffer, 0, buffer.length); 73 | 74 | if (read < 0) { 75 | break; 76 | } 77 | 78 | count += read; 79 | 80 | judgeTransfer(outstream, buffer, read); 81 | 82 | /** 83 | * 判断是否到达单片末尾 Judge whether reach the end of one section 84 | */ 85 | if (count == length) { 86 | Log.d("Test", "count-->" + count); 87 | outstream.flush(); 88 | break; 89 | } 90 | } 91 | 92 | this.consumed = true; 93 | } 94 | 95 | // non-javadoc, see interface HttpEntity 96 | public boolean isStreaming() { 97 | return !this.consumed; 98 | } 99 | 100 | // non-javadoc, see interface HttpEntity 101 | public void consumeContent() throws IOException { 102 | this.consumed = true; 103 | randomAccessFile.close(); 104 | } 105 | 106 | ExecutorService executor = Executors.newSingleThreadExecutor(); 107 | 108 | public boolean judgeTransfer(final OutputStream bos, final byte[] buffer, 109 | final int len) throws IOException { 110 | 111 | Future result = executor.submit(new Callable() { 112 | 113 | @Override 114 | public String call() throws Exception { 115 | 116 | bos.write(buffer, 0, len); 117 | bos.flush(); 118 | 119 | return "success"; 120 | } 121 | }); 122 | 123 | String str; 124 | try { 125 | str = result.get(VDiskAPI.UPLOAD_RESPONSE_TIMEOUT_S, 126 | TimeUnit.SECONDS); 127 | } catch (TimeoutException e) { 128 | e.printStackTrace(); 129 | throw new IOException("Long time no response."); 130 | } catch (Exception e) { 131 | e.printStackTrace(); 132 | throw new IOException(); 133 | } 134 | 135 | if (str != null) { 136 | return true; 137 | } 138 | 139 | return false; 140 | } 141 | 142 | } 143 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/ProgressListener.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.net; 2 | 3 | import java.io.FilterOutputStream; 4 | import java.io.IOException; 5 | import java.io.OutputStream; 6 | 7 | import org.apache.http.HttpEntity; 8 | import org.apache.http.entity.HttpEntityWrapper; 9 | 10 | /** 11 | * Receives file transfer progress updates for some API calls, e.g. getFile and 12 | * putFile. 13 | */ 14 | public abstract class ProgressListener { 15 | 16 | /** 17 | * Gets called when some bytes have been transferred since the last time it 18 | * was called and the progress interval has passed. 19 | * 20 | * @param bytes 21 | * the number of bytes transferred. 22 | * @param total 23 | * the size of the file in bytes. 24 | */ 25 | public abstract void onProgress(long bytes, long total); 26 | 27 | /** 28 | * Should return how often transferred bytes should be reported to this 29 | * listener, in milliseconds. It is not guaranteed that updates will happen 30 | * at this exact interval, but that at least this amount of time will pass 31 | * between updates. The default implementation always returns 500 32 | * milliseconds. 33 | */ 34 | public long progressInterval() { 35 | return 500; 36 | } 37 | 38 | /** 39 | * A wrapper for an {@link HttpEntity} that can count the number of bytes 40 | * transferred. This is used internally to give updates for uploads. 41 | */ 42 | public static class ProgressHttpEntity extends HttpEntityWrapper { 43 | 44 | private final ProgressListener listener; 45 | private final long length; 46 | private long startPos; 47 | 48 | public ProgressHttpEntity(final HttpEntity wrapped, 49 | final ProgressListener listener) { 50 | super(wrapped); 51 | this.listener = listener; 52 | length = wrapped.getContentLength(); 53 | 54 | if (wrapped instanceof ComplexUploadInputStreamEntity) { 55 | startPos = ((ComplexUploadInputStreamEntity) wrapped) 56 | .getStartPosition(); 57 | } 58 | } 59 | 60 | @Override 61 | public void writeTo(OutputStream out) throws IOException { 62 | wrappedEntity.writeTo(new CountingOutputStream(out)); 63 | } 64 | 65 | private class CountingOutputStream extends FilterOutputStream { 66 | private long lastListened = 0; 67 | private long intervalMs = 0; 68 | private long transferred = startPos; 69 | 70 | public CountingOutputStream(final OutputStream out) { 71 | super(out); 72 | intervalMs = listener.progressInterval(); 73 | } 74 | 75 | @Override 76 | public void write(byte[] b, int off, int len) throws IOException { 77 | // Using out.write instead of super.write speeds it up because 78 | // the superclass seems to default to byte-by-byte transfers. 79 | out.write(b, off, len); 80 | transferred += len; 81 | long now = System.currentTimeMillis(); 82 | if (now - lastListened > intervalMs) { 83 | lastListened = now; 84 | listener.onProgress(this.transferred, length); 85 | } 86 | } 87 | 88 | @Override 89 | public void write(int b) throws IOException { 90 | super.write(b); 91 | this.transferred++; 92 | long now = System.currentTimeMillis(); 93 | if (now - lastListened > intervalMs) { 94 | lastListened = now; 95 | listener.onProgress(this.transferred, length); 96 | } 97 | } 98 | } 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/SdkVersion.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.net; 2 | 3 | /** 4 | * Contains the SDK verison number. 5 | */ 6 | public final class SdkVersion { 7 | 8 | /** Returns the SDK version number. */ 9 | public static String get() { 10 | return "1.0"; // Filled in by build process. 11 | } 12 | 13 | public static void main(String[] args) { 14 | System.out.println("VDisk Java SDK, Version " + get()); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/SimpleUploadInputStreamEntity.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.net; 2 | 3 | import java.io.IOException; 4 | import java.io.InputStream; 5 | import java.io.OutputStream; 6 | import java.util.concurrent.Callable; 7 | import java.util.concurrent.ExecutorService; 8 | import java.util.concurrent.Executors; 9 | import java.util.concurrent.Future; 10 | import java.util.concurrent.TimeUnit; 11 | import java.util.concurrent.TimeoutException; 12 | 13 | import org.apache.http.entity.AbstractHttpEntity; 14 | 15 | public class SimpleUploadInputStreamEntity extends AbstractHttpEntity { 16 | 17 | private final static int BUFFER_SIZE = 8192; 18 | 19 | private final InputStream content; 20 | private final long length; 21 | private boolean consumed = false; 22 | 23 | public SimpleUploadInputStreamEntity(final InputStream instream, long length) { 24 | super(); 25 | if (instream == null) { 26 | throw new IllegalArgumentException( 27 | "Source input stream may not be null"); 28 | } 29 | this.content = instream; 30 | this.length = length; 31 | } 32 | 33 | public boolean isRepeatable() { 34 | return false; 35 | } 36 | 37 | public long getContentLength() { 38 | return this.length; 39 | } 40 | 41 | public InputStream getContent() throws IOException { 42 | return this.content; 43 | } 44 | 45 | public void writeTo(final OutputStream outstream) throws IOException { 46 | if (outstream == null) { 47 | throw new IllegalArgumentException("Output stream may not be null"); 48 | } 49 | InputStream instream = this.content; 50 | byte[] buffer = new byte[BUFFER_SIZE]; 51 | int l; 52 | if (this.length < 0) { 53 | // consume until EOF 54 | while ((l = instream.read(buffer)) != -1) { 55 | judgeTransfer(outstream, buffer, l); 56 | } 57 | } else { 58 | // consume no more than length 59 | long remaining = this.length; 60 | while (remaining > 0) { 61 | l = instream.read(buffer, 0, 62 | (int) Math.min(BUFFER_SIZE, remaining)); 63 | if (l == -1) { 64 | break; 65 | } 66 | judgeTransfer(outstream, buffer, l); 67 | remaining -= l; 68 | } 69 | } 70 | this.consumed = true; 71 | } 72 | 73 | // non-javadoc, see interface HttpEntity 74 | public boolean isStreaming() { 75 | return !this.consumed; 76 | } 77 | 78 | // non-javadoc, see interface HttpEntity 79 | public void consumeContent() throws IOException { 80 | this.consumed = true; 81 | // If the input stream is from a connection, closing it will read to 82 | // the end of the content. Otherwise, we don't care what it does. 83 | this.content.close(); 84 | } 85 | 86 | ExecutorService executor = Executors.newSingleThreadExecutor(); 87 | 88 | public boolean judgeTransfer(final OutputStream bos, final byte[] buffer, 89 | final int len) throws IOException { 90 | 91 | Future result = executor.submit(new Callable() { 92 | 93 | @Override 94 | public String call() throws Exception { 95 | 96 | bos.write(buffer, 0, len); 97 | bos.flush(); 98 | 99 | return "success"; 100 | } 101 | }); 102 | 103 | String str; 104 | try { 105 | str = result.get(VDiskAPI.UPLOAD_RESPONSE_TIMEOUT_S, 106 | TimeUnit.SECONDS); 107 | } catch (TimeoutException e) { 108 | e.printStackTrace(); 109 | throw new IOException("Long time no response."); 110 | } catch (Exception e) { 111 | e.printStackTrace(); 112 | throw new IOException(); 113 | } 114 | 115 | if (str != null) { 116 | return true; 117 | } 118 | 119 | return false; 120 | } 121 | 122 | } 123 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/exception/VDiskDialogError.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.net.exception; 2 | 3 | public class VDiskDialogError extends VDiskException { 4 | 5 | private static final long serialVersionUID = 1L; 6 | 7 | private int mErrorCode; 8 | 9 | private String mFailingUrl; 10 | 11 | public VDiskDialogError(String message, int errorCode, String failingUrl) { 12 | super(message); 13 | mErrorCode = errorCode; 14 | mFailingUrl = failingUrl; 15 | } 16 | 17 | int getErrorCode() { 18 | return mErrorCode; 19 | } 20 | 21 | String getFailingUrl() { 22 | return mFailingUrl; 23 | } 24 | 25 | } 26 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/exception/VDiskDownloadFileExistException.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.net.exception; 2 | 3 | public class VDiskDownloadFileExistException extends VDiskException{ 4 | 5 | private static final long serialVersionUID = 1L; 6 | 7 | public VDiskDownloadFileExistException() { 8 | super(); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/exception/VDiskException.java: -------------------------------------------------------------------------------- 1 | 2 | package com.vdisk.net.exception; 3 | 4 | /** 5 | * A base for all exceptions from using the API. Catch this instead of specific 6 | * subclasses when you want to deal with those issues in a generic way. 7 | */ 8 | public class VDiskException extends Exception { 9 | 10 | private static final long serialVersionUID = 1L; 11 | 12 | protected VDiskException() { 13 | super(); 14 | } 15 | 16 | public VDiskException(String detailMessage) { 17 | super(detailMessage); 18 | } 19 | 20 | public VDiskException(String detailMessage, Throwable throwable) { 21 | super(detailMessage, throwable); 22 | } 23 | 24 | public VDiskException(Throwable throwable) { 25 | super(throwable); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/exception/VDiskFileNotFoundException.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.net.exception; 2 | 3 | import java.io.IOException; 4 | 5 | public class VDiskFileNotFoundException extends VDiskException { 6 | 7 | private static final long serialVersionUID = 1L; 8 | 9 | public VDiskFileNotFoundException(IOException e) { 10 | super(e); 11 | } 12 | 13 | } 14 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/exception/VDiskFileSizeException.java: -------------------------------------------------------------------------------- 1 | 2 | package com.vdisk.net.exception; 3 | 4 | /** 5 | * Thrown when trying to upload a file larger than the API can handle. See 6 | * {@link VDiskAPI#MAX_UPLOAD_SIZE}. 7 | */ 8 | public class VDiskFileSizeException extends VDiskException { 9 | private static final long serialVersionUID = 1L; 10 | 11 | public VDiskFileSizeException(String s) { 12 | super(s); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/exception/VDiskIOException.java: -------------------------------------------------------------------------------- 1 | 2 | package com.vdisk.net.exception; 3 | 4 | import java.io.IOException; 5 | 6 | /** 7 | * Encapsulates an IOExceptions when using the API, typically resulting from 8 | * network-related issues. 9 | */ 10 | public class VDiskIOException extends VDiskException { 11 | private static final long serialVersionUID = 2L; 12 | 13 | public VDiskIOException(IOException e) { 14 | super(e); 15 | } 16 | 17 | public VDiskIOException(String detailMessage) { 18 | super(detailMessage); 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/exception/VDiskLocalStorageFullException.java: -------------------------------------------------------------------------------- 1 | 2 | package com.vdisk.net.exception; 3 | 4 | /** 5 | * Thrown when writing to local storage and there is no more room. 6 | */ 7 | public class VDiskLocalStorageFullException extends VDiskException { 8 | private static final long serialVersionUID = 2L; 9 | 10 | public VDiskLocalStorageFullException() {} 11 | } 12 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/exception/VDiskParseException.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.net.exception; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | 6 | import com.vdisk.utils.Logger; 7 | 8 | /** 9 | * Indicates there was trouble parsing a response from VDisk. 10 | */ 11 | public class VDiskParseException extends VDiskException { 12 | private static final long serialVersionUID = 1L; 13 | 14 | /* 15 | * Takes a BufferedReader so it can be reset back to the beginning and read 16 | * again into the body variable. 17 | */ 18 | public VDiskParseException(BufferedReader reader) { 19 | super("failed to parse: " + stringifyBody(reader)); 20 | 21 | if (Logger.DEBUG_MODE) { 22 | Logger.writeToFile(stringifyBody(reader)); 23 | } 24 | } 25 | 26 | public static String stringifyBody(BufferedReader reader) { 27 | String inputLine = null; 28 | 29 | try { 30 | if (reader != null) { 31 | reader.reset(); 32 | } 33 | } catch (IOException ioe) { 34 | } 35 | StringBuffer result = new StringBuffer(); 36 | try { 37 | while ((inputLine = reader.readLine()) != null) { 38 | result.append(inputLine); 39 | } 40 | } catch (IOException e) { 41 | } 42 | 43 | return result.toString(); 44 | } 45 | 46 | public VDiskParseException(String message) { 47 | super(message); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/exception/VDiskPartialFileException.java: -------------------------------------------------------------------------------- 1 | 2 | package com.vdisk.net.exception; 3 | 4 | /** 5 | * Used when only part of a file was transferred to/from VDisk when using the 6 | * API. 7 | */ 8 | public class VDiskPartialFileException extends VDiskException { 9 | private static final long serialVersionUID = 2L; 10 | 11 | /** 12 | * The number of bytes successfully transferred. 13 | */ 14 | public final long bytesTransferred; 15 | 16 | public VDiskPartialFileException(long transferred) { 17 | bytesTransferred = transferred; 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/exception/VDiskSSLException.java: -------------------------------------------------------------------------------- 1 | 2 | package com.vdisk.net.exception; 3 | 4 | import javax.net.ssl.SSLException; 5 | 6 | /** 7 | * Wraps any SSL-related exceptions thrown when using the API. 8 | */ 9 | public class VDiskSSLException extends VDiskIOException { 10 | 11 | private static final long serialVersionUID = 1L; 12 | 13 | public VDiskSSLException(SSLException e) { 14 | super(e); 15 | } 16 | 17 | } 18 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/exception/VDiskUnlinkedException.java: -------------------------------------------------------------------------------- 1 | 2 | package com.vdisk.net.exception; 3 | 4 | import com.vdisk.net.session.AccessToken; 5 | 6 | /** 7 | * Thrown when the API can only be used when linked but it's not. This will 8 | * happen either because you have not set an {@link AccessToken} on your 9 | * session, or because the user unlinked your app (revoked the access token 10 | * pair). 11 | */ 12 | public class VDiskUnlinkedException extends VDiskException { 13 | private static final long serialVersionUID = 1L; 14 | 15 | public VDiskUnlinkedException() { 16 | super(); 17 | } 18 | 19 | public VDiskUnlinkedException(String message) { 20 | super(message); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/jsonextract/JsonBase.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.net.jsonextract; 2 | 3 | /** 4 | * (Internal class for extracting JSON.) 5 | */ 6 | abstract class JsonBase { 7 | public final T internal; 8 | public final String path; 9 | 10 | public JsonBase(T internal) { 11 | this(internal, null); 12 | } 13 | 14 | public JsonBase(T internal, String path) { 15 | this.internal = internal; 16 | this.path = path; 17 | } 18 | 19 | public JsonExtractionException error(String message) { 20 | return new JsonExtractionException(path, message, internal); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/jsonextract/JsonExtractionException.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.net.jsonextract; 2 | 3 | import static org.json.simple.JSONValue.toJSONString; 4 | 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | public final class JsonExtractionException extends Exception { 9 | 10 | private static final long serialVersionUID = 1L; 11 | 12 | public JsonExtractionException(String path, String message, Object value) { 13 | super((path == null ? "" : path + ": ") + message + 14 | (value == null ? "" : ": " + summarizeValue(value))); 15 | } 16 | 17 | private static String summarizeValue(Object value) { 18 | if (value instanceof java.util.Map) { 19 | StringBuilder buf = new StringBuilder(); 20 | @SuppressWarnings("unchecked") 21 | Map map = (Map) value; 22 | buf.append("{"); 23 | String sep = ""; 24 | for (Map.Entry entry : map.entrySet()) { 25 | buf.append(sep); sep = ", "; 26 | buf.append(toJSONString(entry.getKey())); 27 | buf.append(" = "); 28 | buf.append("..."); 29 | } 30 | buf.append("}"); 31 | return buf.toString(); 32 | } 33 | else if (value instanceof java.util.List) { 34 | @SuppressWarnings("rawtypes") 35 | List list = (List) value; 36 | if (list.isEmpty()) { 37 | return "[]"; 38 | } else if (list.size() == 1) { 39 | return "[" + summarizeValue(list.get(0)) + "]"; 40 | } else { 41 | return "[" + summarizeValue(list.get(0)) + ", ...] (" + list.size() + " elements)"; 42 | } 43 | } 44 | else { 45 | return toJSONString(value); 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/jsonextract/JsonExtractor.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.net.jsonextract; 2 | 3 | public abstract class JsonExtractor { 4 | public abstract T extract(JsonThing jt) throws JsonExtractionException; 5 | } 6 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/jsonextract/JsonList.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.net.jsonextract; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Iterator; 5 | import java.util.List; 6 | 7 | /** 8 | * (Internal class for extracting JSON.) 9 | * 10 | * A JSON "array" (a list of arbitrary JSON values). 11 | */ 12 | public final class JsonList extends JsonBase> implements Iterable { 13 | 14 | public JsonList(java.util.List internal, String path) { 15 | super(internal, path); 16 | } 17 | 18 | public JsonList(java.util.List internal) { 19 | super(internal); 20 | } 21 | 22 | private static String pathConcatIndex(String path, int index) { 23 | return JsonThing.pathConcat(path, Integer.toString(index)); 24 | } 25 | 26 | public JsonThing get(int index) throws JsonExtractionException { 27 | if (index >= internal.size()) { 28 | throw error("expecting array to have an element at index " + index + ", but it only has length " + internal.size()); 29 | } 30 | return new JsonThing(internal.get(index), pathConcatIndex(path, index)); 31 | } 32 | 33 | public void expectLength(int length) throws JsonExtractionException { 34 | if (internal.size() != length) { 35 | throw error("expecting array to have length " + length + ", but it has length " + internal.size()); 36 | } 37 | } 38 | 39 | public int length() { 40 | return internal.size(); 41 | } 42 | 43 | private static final class WrapperIterator implements Iterator { 44 | private int numReturned = 0; 45 | private final String path; 46 | private final Iterator internal; 47 | private WrapperIterator(String path, Iterator internal) { 48 | this.path = path; 49 | this.internal = internal; 50 | } 51 | 52 | public boolean hasNext() { return internal.hasNext(); } 53 | public void remove() { throw new UnsupportedOperationException("can't remove"); } 54 | 55 | public JsonThing next() { 56 | int index = numReturned++; 57 | return new JsonThing(internal.next(), pathConcatIndex(path, index)); 58 | } 59 | } 60 | 61 | public Iterator iterator() { 62 | return new WrapperIterator(path, internal.iterator()); 63 | } 64 | 65 | public static final class Extractor extends JsonExtractor> { 66 | public final JsonExtractor elementExtractor; 67 | public Extractor(JsonExtractor elementExtractor) { 68 | this.elementExtractor = elementExtractor; 69 | } 70 | 71 | public List extract(JsonThing jt) throws JsonExtractionException { 72 | return jt.expectList().extract(this.elementExtractor); 73 | } 74 | } 75 | 76 | public ArrayList extract(JsonExtractor elementExtractor) throws JsonExtractionException { 77 | ArrayList result = new ArrayList(length()); 78 | for (Object o : internal) { 79 | result.add(elementExtractor.extract(new JsonThing(o))); 80 | } 81 | return result; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/jsonextract/JsonMap.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.net.jsonextract; 2 | 3 | import java.util.Iterator; 4 | import java.util.Map; 5 | 6 | /** 7 | * (Internal class for extracting JSON.) 8 | * 9 | * A JSON "object" (a mapping of string keys to arbitrary JSON values). 10 | */ 11 | public final class JsonMap extends JsonBase> implements Iterable> { 12 | 13 | public JsonMap(Map internal, String path) { 14 | super(internal, path); 15 | } 16 | 17 | public JsonMap(Map internal) { 18 | super(internal); 19 | } 20 | 21 | private static boolean isIdentLike(String s) { 22 | if (s.length() == 0) return false; 23 | if (!isEnglishLetter(s.charAt(0))) return false; 24 | for (int i = 1; i < s.length(); i++) { 25 | char c = s.charAt(i); 26 | if (!isEnglishLetter(c) && !isEnglishDigit(c)) return false; 27 | } 28 | return true; 29 | } 30 | 31 | private static boolean isEnglishLetter(char c) { 32 | return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'); 33 | } 34 | 35 | private static boolean isEnglishDigit(char c) { 36 | return c >= '0' && c <= '9'; 37 | } 38 | 39 | private static String pathConcatField(String path, String fieldName) { 40 | String suffix = fieldName; 41 | if (!isIdentLike(fieldName)) { 42 | suffix = '"' + fieldName + '"'; // TODO: Proper JSON quoting. 43 | } 44 | return JsonThing.pathConcat(path, suffix); 45 | } 46 | 47 | public JsonThing get(String fieldName) throws JsonExtractionException { 48 | if (!internal.containsKey(fieldName)) { 49 | throw error("expecting object to have field \"" + fieldName + "\", but it does not"); 50 | } 51 | return new JsonThing(internal.get(fieldName), pathConcatField(path, fieldName)); 52 | } 53 | 54 | public JsonThing getMaybe(String fieldName) { 55 | if (!internal.containsKey(fieldName)) { 56 | return null; 57 | } 58 | return new JsonThing(internal.get(fieldName), pathConcatField(path, fieldName)); 59 | } 60 | 61 | /** 62 | * A key+value iterator that automatically wraps every value in a JsonThing. 63 | */ 64 | private static final class WrapperIterator implements Iterator> { 65 | private final String path; 66 | private final Iterator> internal; 67 | 68 | private WrapperIterator(String path, Iterator> internal) { 69 | this.path = path; 70 | this.internal = internal; 71 | } 72 | 73 | public boolean hasNext() { return internal.hasNext(); } 74 | public Map.Entry next() { 75 | return new WrappedEntry(path, internal.next()); 76 | } 77 | public void remove() { throw new UnsupportedOperationException("can't remove"); } 78 | } 79 | 80 | private static final class WrappedEntry implements Map.Entry { 81 | private final String key; 82 | private final JsonThing value; 83 | 84 | private WrappedEntry(String path, Map.Entry original) { 85 | this.key = original.getKey(); 86 | this.value = new JsonThing(original.getValue(), pathConcatField(path, key)); 87 | } 88 | 89 | public String getKey() { return key; } 90 | public JsonThing getValue() { return value; } 91 | public JsonThing setValue(JsonThing jsonThing) { throw new UnsupportedOperationException(); } 92 | } 93 | 94 | public Iterator> iterator() { 95 | return new WrapperIterator(path, internal.entrySet().iterator()); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/session/AccessToken.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.net.session; 2 | 3 | import org.json.JSONException; 4 | import org.json.JSONObject; 5 | 6 | import com.vdisk.android.VDiskDialogListener; 7 | import com.vdisk.net.exception.VDiskException; 8 | 9 | /** 10 | *

11 | * Holds a user's access token. 12 | *

13 | */ 14 | public class AccessToken extends Token { 15 | 16 | private static final long serialVersionUID = 1L; 17 | 18 | public AccessToken() { 19 | 20 | } 21 | 22 | public AccessToken(String rltString, VDiskDialogListener listener) { 23 | if (rltString != null) { 24 | if (rltString.indexOf("{") >= 0) { 25 | try { 26 | JSONObject json = new JSONObject(rltString); 27 | mAccessToken = json.getString("access_token"); 28 | mExpiresIn = json.getString("expires_in"); 29 | mRefreshToken = json.optString("refresh_token"); 30 | mUid = json.optString("uid"); 31 | } catch (JSONException e) { 32 | listener.onVDiskException(new VDiskException( 33 | "Fail get Access Token,Refresh token valid")); 34 | } 35 | } 36 | } 37 | } 38 | 39 | } 40 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/session/AppKeyPair.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.net.session; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | *

7 | * Holds your app's key and secret. 8 | *

9 | */ 10 | public final class AppKeyPair implements Serializable { 11 | 12 | private static final long serialVersionUID = 1L; 13 | 14 | /** 15 | * The "key" portion of the pair. For example, the "consumer key", 16 | * "request token", or "access token". Will never contain the "|" 17 | * character. 18 | */ 19 | public final String key; 20 | 21 | /** 22 | * The "secret" portion of the pair. For example, the "consumer secret", 23 | * "request token secret", or "access token secret". 24 | */ 25 | public final String secret; 26 | 27 | /** 28 | * @param key assigned to {@link #key}. 29 | * @param secret assigned to {@link #secret}. 30 | * 31 | * @throws IllegalArgumentException if key or secret is null or invalid. 32 | */ 33 | public AppKeyPair(String key, String secret) { 34 | if (key == null) 35 | throw new IllegalArgumentException("'key' must be non-null"); 36 | if (key.contains("|")) 37 | throw new IllegalArgumentException("'key' must not contain a \"|\" character: \"" + key + "\""); 38 | if (secret == null) 39 | throw new IllegalArgumentException("'secret' must be non-null"); 40 | 41 | this.key = key; 42 | this.secret = secret; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/session/RetryHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | Android Asynchronous Http Client 3 | Copyright (c) 2011 James Smith 4 | http://loopj.com 5 | 6 | Licensed under the Apache License, Version 2.0 (the "License"); 7 | you may not use this file except in compliance with the License. 8 | You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, software 13 | distributed under the License is distributed on an "AS IS" BASIS, 14 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | See the License for the specific language governing permissions and 16 | limitations under the License. 17 | */ 18 | 19 | /* 20 | Some of the retry logic in this class is heavily borrowed from the 21 | fantastic droid-fu project: https://github.com/donnfelker/droid-fu 22 | */ 23 | 24 | package com.vdisk.net.session; 25 | 26 | import java.io.IOException; 27 | import java.io.InterruptedIOException; 28 | import java.net.SocketException; 29 | import java.net.UnknownHostException; 30 | import java.util.HashSet; 31 | 32 | import javax.net.ssl.SSLHandshakeException; 33 | 34 | import org.apache.http.NoHttpResponseException; 35 | import org.apache.http.client.HttpRequestRetryHandler; 36 | import org.apache.http.client.methods.HttpUriRequest; 37 | import org.apache.http.protocol.ExecutionContext; 38 | import org.apache.http.protocol.HttpContext; 39 | 40 | import android.os.SystemClock; 41 | import android.util.Log; 42 | 43 | class RetryHandler implements HttpRequestRetryHandler { 44 | private static final int RETRY_SLEEP_TIME_MILLIS = 1000; 45 | private static HashSet> exceptionWhitelist = new HashSet>(); 46 | private static HashSet> exceptionBlacklist = new HashSet>(); 47 | 48 | static { 49 | // Retry if the server dropped connection on us 50 | exceptionWhitelist.add(NoHttpResponseException.class); 51 | // retry-this, since it may happens as part of a Wi-Fi to 3G failover 52 | exceptionWhitelist.add(UnknownHostException.class); 53 | // retry-this, since it may happens as part of a Wi-Fi to 3G failover 54 | exceptionWhitelist.add(SocketException.class); 55 | 56 | // never retry timeouts 57 | exceptionBlacklist.add(InterruptedIOException.class); 58 | // never retry SSL handshake failures 59 | exceptionBlacklist.add(SSLHandshakeException.class); 60 | } 61 | 62 | private final int maxRetries; 63 | 64 | public RetryHandler(int maxRetries) { 65 | this.maxRetries = maxRetries; 66 | } 67 | 68 | public boolean retryRequest(IOException exception, int executionCount, HttpContext context) { 69 | boolean retry = true; 70 | 71 | Log.d("Test", "retry count->" + executionCount); 72 | 73 | Boolean b = (Boolean) context.getAttribute(ExecutionContext.HTTP_REQ_SENT); 74 | boolean sent = (b != null && b.booleanValue()); 75 | 76 | if(executionCount > maxRetries) { 77 | // Do not retry if over max retry count 78 | retry = false; 79 | } else if (exceptionBlacklist.contains(exception.getClass())) { 80 | // immediately cancel retry if the error is blacklisted 81 | retry = false; 82 | } else if (exceptionWhitelist.contains(exception.getClass())) { 83 | // immediately retry if error is whitelisted 84 | retry = true; 85 | } else if (!sent) { 86 | // for most other errors, retry only if request hasn't been fully sent yet 87 | retry = true; 88 | } 89 | 90 | if(retry) { 91 | // resend all idempotent requests 92 | HttpUriRequest currentReq = (HttpUriRequest) context.getAttribute( ExecutionContext.HTTP_REQUEST ); 93 | 94 | Log.d("Test", "HttpUriRequest:" + currentReq); 95 | if(currentReq!=null) { 96 | String requestType = currentReq.getMethod(); 97 | retry = !requestType.equals("POST") && !requestType.equals("PUT"); 98 | } 99 | 100 | } 101 | 102 | if(retry) { 103 | SystemClock.sleep(RETRY_SLEEP_TIME_MILLIS); 104 | } else { 105 | exception.printStackTrace(); 106 | } 107 | 108 | return retry; 109 | } 110 | } -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/session/Session.java: -------------------------------------------------------------------------------- 1 | 2 | package com.vdisk.net.session; 3 | 4 | import org.apache.http.HttpRequest; 5 | import org.apache.http.client.HttpClient; 6 | import org.apache.http.client.methods.HttpUriRequest; 7 | 8 | import android.content.Context; 9 | 10 | import com.vdisk.net.VDiskAPI; 11 | 12 | /** 13 | * Keeps track of a logged in user. Contains configuration options for the 14 | * {@link VDiskAPI}. 15 | */ 16 | public interface Session { 17 | 18 | /** 19 | * Returns the app key and secret. 20 | */ 21 | public AppKeyPair getAppKeyPair(); 22 | 23 | /** 24 | * Returns the currently logged in user's access token. 25 | */ 26 | public AccessToken getAccessToken(); 27 | 28 | /** 29 | * Returns the currently logged in user's Weibo access token. 30 | */ 31 | public AccessToken getWeiboAccessToken(); 32 | 33 | /** 34 | * Returns what VDisk access type to use (currently app folder or entire 35 | * VDisk). 36 | */ 37 | public AccessType getAccessType(); 38 | 39 | /** 40 | * Returns whether or not this session has a user's access token and 41 | * secret. 42 | */ 43 | public boolean isLinked(); 44 | 45 | /** 46 | * Unlinks the session by removing any stored access token and secret. 47 | */ 48 | public void unlink(); 49 | 50 | /** 51 | * OAuth signs the request with the currently-set tokens and secrets. 52 | * 53 | * @param request an {@link HttpRequest}. 54 | */ 55 | public void sign(HttpRequest request); 56 | 57 | /** 58 | * Will be called every time a request is made to VDisk, in case the 59 | * proxy changes between requests. Return null if you do not want to use 60 | * a proxy, or a {@link ProxyInfo} object with a host and optionally a 61 | * port set. 62 | */ 63 | public ProxyInfo getProxyInfo(); 64 | 65 | /** 66 | * Will be called every time a request is made to VDisk, in case you want 67 | * to use a new client every time. However, it's highly recommended to 68 | * create a client once and reuse it to take advantage of connection reuse. 69 | */ 70 | public HttpClient getHttpClient(); 71 | 72 | /** 73 | * Will be called every time right before a request is sent to VDisk. It 74 | * should set the socket and connection timeouts on the request if you want 75 | * to override the default values. This is abstracted out to cope with 76 | * signature changes in the Apache HttpClient libraries. 77 | */ 78 | public void setRequestTimeout(HttpUriRequest request); 79 | 80 | /** 81 | * Returns the VDisk API server. Changing this will break things. 82 | */ 83 | public String getAPIServer(); 84 | 85 | /** 86 | * Returns the VDisk content server. Changing this will break things. 87 | */ 88 | // public String getContentServer(); 89 | 90 | /** 91 | * Returns the VDisk web server. Changing this will break things. 92 | */ 93 | // public String getWebServer(); 94 | 95 | /** 96 | * Returns the VDisk upload server. Changing this will break things. 97 | */ 98 | public String getUploadServer(); 99 | 100 | public Context getContext(); 101 | 102 | public enum AccessType { 103 | VDISK("basic"), APP_FOLDER("sandbox"); 104 | 105 | private final String urlPart; 106 | 107 | private AccessType(String urlPart) { 108 | this.urlPart = urlPart; 109 | } 110 | 111 | @Override 112 | public String toString() { 113 | return urlPart; 114 | } 115 | } 116 | 117 | /** 118 | * Describes a proxy. 119 | */ 120 | public static final class ProxyInfo { 121 | /** The address of the proxy. */ 122 | public final String host; 123 | 124 | /** The port of the proxy, or -1 to use the default port. */ 125 | public final int port; 126 | 127 | /** 128 | * Creates a proxy info. 129 | * 130 | * @param host the host to use without a protocol (required). 131 | * @param port the port to use, or -1 for default port. 132 | */ 133 | public ProxyInfo(String host, int port) { 134 | this.host = host; 135 | this.port = port; 136 | } 137 | 138 | /** 139 | * Creates a proxy info using the default port. 140 | * 141 | * @param host the host to use without a protocol (required). 142 | */ 143 | public ProxyInfo(String host) { 144 | this(host, -1); 145 | } 146 | } 147 | } 148 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/session/Token.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.net.session; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * A token base class. 7 | * 8 | * @author sina 9 | */ 10 | public class Token implements Serializable { 11 | 12 | private static final long serialVersionUID = -8762944288133769081L; 13 | 14 | /** 15 | * AccessToken,用户验证的唯一标识. 16 | * 17 | * The unique identifier of the user authentication 18 | */ 19 | public String mAccessToken = ""; 20 | 21 | /** 22 | * 使用此RefreshToken可以对AccessToken进行刷新,从而可以不用登录,就得到最新的AccessToken(仅限于某些高级权限的应用 23 | * ); 24 | * 25 | * Use this RefreshToken to refresh AccessToken, so that you needn't to 26 | * login again to get the new AccessToken(limited to some applications with 27 | * advanced permission). 28 | */ 29 | public String mRefreshToken = ""; 30 | 31 | /** 32 | * token的有效期,在此时间点之前,token都有效,是一个时间戳,单位是秒. 33 | * 34 | * Expire time of token. Token is available before this time. It is a time 35 | * stamp, its unit is seconds. 36 | * 37 | */ 38 | public String mExpiresIn = ""; 39 | 40 | /** 41 | * 用户的微博uid 42 | * 43 | * User's Weibo uid 44 | */ 45 | public String mUid = ""; 46 | 47 | public Token() { 48 | 49 | } 50 | 51 | public Token(String accessToken) { 52 | this.mAccessToken = accessToken; 53 | } 54 | 55 | public String getToken() { 56 | return mAccessToken; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/net/session/WeiboAccessToken.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.net.session; 2 | 3 | /** 4 | *

5 | * Holds a user's Weibo access token. 6 | *

7 | */ 8 | public class WeiboAccessToken extends AccessToken { 9 | 10 | private static final long serialVersionUID = 1L; 11 | 12 | public WeiboAccessToken() { 13 | 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/utils/Config.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.utils; 2 | 3 | import com.vdisk.net.VDiskAPI; 4 | import com.vdisk.net.session.AbstractSession; 5 | 6 | public class Config { 7 | 8 | /** 9 | * If DEBUG_MODE == true, every api request information will be wrote to 10 | * local file (default path is "sdcard/vdisk/api.log"), else, we won't write 11 | * to the local file. 12 | */ 13 | public static void setDebugMode(boolean debugMode) { 14 | Logger.DEBUG_MODE = debugMode; 15 | } 16 | 17 | /** 18 | * Returns whether sdk is debug mode or not. 19 | * 20 | * @return 21 | */ 22 | public static boolean isDebugMode() { 23 | return Logger.DEBUG_MODE; 24 | } 25 | 26 | /** 27 | * Set the debug log path manually, default path is "sdcard/vdisk/api.log". 28 | * 29 | * @param path 30 | */ 31 | public static void setDebugLogPath(String path) { 32 | if (path != null) { 33 | Logger.logPath = path; 34 | } 35 | } 36 | 37 | /** 38 | * Returns the debug log path. 39 | * 40 | * @return 41 | */ 42 | public static String getDebugLogPath() { 43 | return Logger.logPath; 44 | } 45 | 46 | /** 47 | * If needHttps = true, use https to upload a file in the api of 48 | * "/files_put/" 49 | * 50 | * @param needHttps 51 | */ 52 | public static void setHttpsUpload(boolean needHttps) { 53 | AbstractSession.NEED_HTTPS_UPLOAD = needHttps; 54 | } 55 | 56 | /** 57 | * Return whether use https or http for upload. 58 | * @return 59 | */ 60 | public static boolean isHttpsUpload() { 61 | return AbstractSession.NEED_HTTPS_UPLOAD; 62 | } 63 | 64 | /** 65 | * Set the upload socket timeout in millisecond. Default is 1 minute. 66 | * @param ms 67 | */ 68 | public static void setUploadSocketTimeout(int ms) { 69 | if (ms > 0) { 70 | VDiskAPI.UPLOAD_SO_TIMEOUT_MS = ms; 71 | } 72 | } 73 | 74 | /** 75 | * Get the upload socket timeout. 76 | * @return 77 | */ 78 | public static int getUploadSocketTimeout() { 79 | return VDiskAPI.UPLOAD_SO_TIMEOUT_MS; 80 | } 81 | 82 | /** 83 | * Set the upload response timeout. Default is 20 seconds. 84 | * @param s 85 | */ 86 | public static void setUploadResponseTimeout(int s) { 87 | if (s > 0) { 88 | VDiskAPI.UPLOAD_RESPONSE_TIMEOUT_S = s; 89 | } 90 | } 91 | 92 | /** 93 | * Get the upload response timeout. 94 | * @return 95 | */ 96 | public static int getUploadResponseTimeout() { 97 | return VDiskAPI.UPLOAD_RESPONSE_TIMEOUT_S; 98 | } 99 | 100 | } 101 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/utils/DesEncrypt.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.utils; 2 | 3 | import java.security.Key; 4 | import java.security.SecureRandom; 5 | import java.security.spec.KeySpec; 6 | 7 | import javax.crypto.Cipher; 8 | import javax.crypto.KeyGenerator; 9 | import javax.crypto.SecretKeyFactory; 10 | import javax.crypto.spec.DESKeySpec; 11 | 12 | import android.text.TextUtils; 13 | 14 | import com.vdisk.net.session.AppKeyPair; 15 | 16 | /** 17 | * DES加密解密算法,此方法用于将微盘token加密后保存到SharedPreferences中. 18 | * 使用时从SharedPreferences读取出来,通过此方法解密后使用. 19 | * 20 | * DES encryption and decryption algorithm. This method is used to encrypt VDisk 21 | * token and save it in SharedPreferences. Read it from SharedPreferences and 22 | * decrypt it to use. 23 | * 24 | * @author sina 25 | * 26 | */ 27 | public class DesEncrypt { 28 | private Key key; 29 | private String PASSWORD; 30 | 31 | public DesEncrypt(String IMEI, AppKeyPair appKeyPair) { 32 | this.PASSWORD = "com.sina.vdisk.security.password.d7af3082d815945ff47ae58647bd9436" 33 | + IMEI + appKeyPair.key + appKeyPair.secret; 34 | } 35 | 36 | protected void setKey(String strKey) { 37 | KeyGenerator _generator; 38 | try { 39 | _generator = KeyGenerator.getInstance("DES"); 40 | _generator.init(new SecureRandom(strKey.getBytes())); 41 | KeySpec keySpec = new DESKeySpec(strKey.getBytes()); 42 | SecretKeyFactory factory = SecretKeyFactory.getInstance("DES"); 43 | Key key = factory.generateSecret(keySpec); 44 | this.key = key; 45 | _generator = null; 46 | } catch (Exception e) { 47 | e.printStackTrace(); 48 | } 49 | } 50 | 51 | public String getEncString(String strMing) { 52 | String strMi = ""; 53 | try { 54 | return byte2hex(getEncCode(strMing.getBytes())); 55 | } catch (Exception e) { 56 | e.printStackTrace(); 57 | } 58 | 59 | return strMi; 60 | } 61 | 62 | public String getDesString(String strMi) { 63 | String strMing = ""; 64 | try { 65 | if (!TextUtils.isEmpty(strMi)) { 66 | return new String(getDesCode(hex2byte(strMi.getBytes()))); 67 | } 68 | } catch (Exception e) { 69 | e.printStackTrace(); 70 | } 71 | 72 | return strMing; 73 | } 74 | 75 | private void validateKey() { 76 | if (this.key == null) 77 | setKey(PASSWORD); 78 | } 79 | 80 | private byte[] getEncCode(byte[] byteS) { 81 | Cipher cipher; 82 | byte[] byteFina = (byte[]) null; 83 | try { 84 | validateKey(); 85 | cipher = Cipher.getInstance("DES"); 86 | cipher.init(1, this.key); 87 | byteFina = cipher.doFinal(byteS); 88 | } catch (Exception e) { 89 | e.printStackTrace(); 90 | 91 | cipher = null; 92 | } finally { 93 | cipher = null; 94 | } 95 | return byteFina; 96 | } 97 | 98 | private byte[] getDesCode(byte[] byteD) { 99 | Cipher cipher; 100 | byte[] byteFina = (byte[]) null; 101 | try { 102 | validateKey(); 103 | cipher = Cipher.getInstance("DES"); 104 | cipher.init(2, this.key); 105 | byteFina = cipher.doFinal(byteD); 106 | } catch (Exception e) { 107 | e.printStackTrace(); 108 | 109 | cipher = null; 110 | } finally { 111 | cipher = null; 112 | } 113 | return byteFina; 114 | } 115 | 116 | public static String byte2hex(byte[] b) { 117 | String hs = ""; 118 | String stmp = ""; 119 | for (int n = 0; n < b.length; ++n) { 120 | stmp = Integer.toHexString(b[n] & 0xFF); 121 | if (stmp.length() == 1) 122 | hs = hs + "0" + stmp; 123 | else 124 | hs = hs + stmp; 125 | } 126 | return hs.toUpperCase(); 127 | } 128 | 129 | public static byte[] hex2byte(byte[] b) { 130 | if (b.length % 2 != 0) 131 | throw new IllegalArgumentException("length error"); 132 | byte[] b2 = new byte[b.length / 2]; 133 | for (int n = 0; n < b.length; n += 2) { 134 | String item = new String(b, n, 2); 135 | 136 | b2[(n / 2)] = (byte) Integer.parseInt(item, 16); 137 | } 138 | return b2; 139 | } 140 | 141 | } -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/utils/Logger.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.utils; 2 | 3 | import java.io.File; 4 | import java.io.FileNotFoundException; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.text.SimpleDateFormat; 8 | import java.util.Date; 9 | import java.util.Locale; 10 | 11 | import android.content.Context; 12 | import android.net.ConnectivityManager; 13 | import android.net.NetworkInfo; 14 | import android.os.Environment; 15 | import android.text.TextUtils; 16 | 17 | public class Logger { 18 | 19 | /** 20 | * If DEBUG_MODE == true, every api request information will be wrote to 21 | * local file (sdcard/vdisk/api.log), else, we won't write to the local 22 | * file. 23 | */ 24 | public static boolean DEBUG_MODE = false; 25 | 26 | public static String logPath = Environment 27 | .getExternalStorageDirectory().getAbsolutePath() + "/vdisk"; 28 | 29 | public static synchronized void writeToFile(String message) { 30 | if (TextUtils.isEmpty(message)) { 31 | return; 32 | } 33 | 34 | File dirFile = new File(logPath); 35 | 36 | if (!dirFile.exists()) { 37 | dirFile.mkdirs(); 38 | } 39 | 40 | File file = new File(logPath + "/api.log"); 41 | 42 | FileOutputStream fos = null; 43 | try { 44 | fos = new FileOutputStream(file, true); 45 | fos.write(message.getBytes()); 46 | fos.write("\n".getBytes()); 47 | fos.flush(); 48 | } catch (FileNotFoundException e) { 49 | e.printStackTrace(); 50 | } catch (IOException e) { 51 | e.printStackTrace(); 52 | } finally { 53 | try { 54 | if (fos != null) { 55 | fos.close(); 56 | } 57 | } catch (IOException e) { 58 | e.printStackTrace(); 59 | } 60 | } 61 | } 62 | 63 | public static void writeHeader(Context context) { 64 | Logger.writeToFile("\n\n"); 65 | SimpleDateFormat dateFormat = new SimpleDateFormat( 66 | "[dd/MMM/yyyy:HH:mm:ss ZZZ]", Locale.US); 67 | Logger.writeToFile(dateFormat.format(new Date())); 68 | 69 | switch (getNetworkState(context)) { 70 | case MOBILE: 71 | Logger.writeToFile("network state: 3G"); 72 | break; 73 | case WIFI: 74 | Logger.writeToFile("network state: wifi"); 75 | break; 76 | case NOTHING: 77 | Logger.writeToFile("network state: no"); 78 | break; 79 | } 80 | } 81 | 82 | public static void writeException(Throwable e) { 83 | if (e != null) { 84 | Logger.writeToFile(e.getClass().getName() + ":" + e.getMessage()); 85 | } 86 | } 87 | 88 | public static void writeException(String msg, Throwable e) { 89 | if (e != null) { 90 | Logger.writeToFile(msg + " " + e.getClass().getName() + ":" 91 | + e.getMessage()); 92 | } 93 | } 94 | 95 | public enum NetworkState { 96 | NOTHING, MOBILE, WIFI 97 | } 98 | 99 | public static NetworkState getNetworkState(Context ctx) { 100 | ConnectivityManager cm = (ConnectivityManager) ctx 101 | .getSystemService(Context.CONNECTIVITY_SERVICE); 102 | NetworkInfo info = cm.getActiveNetworkInfo(); 103 | if (info == null || !info.isAvailable()) { 104 | return NetworkState.NOTHING; 105 | } else { 106 | if (info.getType() == ConnectivityManager.TYPE_MOBILE) { 107 | return NetworkState.MOBILE; 108 | } else { 109 | return NetworkState.WIFI; 110 | } 111 | } 112 | } 113 | 114 | } 115 | -------------------------------------------------------------------------------- /VDiskSdk/src/com/vdisk/utils/Signature.java: -------------------------------------------------------------------------------- 1 | package com.vdisk.utils; 2 | 3 | import java.io.UnsupportedEncodingException; 4 | import java.security.InvalidKeyException; 5 | import java.security.NoSuchAlgorithmException; 6 | import java.util.Date; 7 | import java.util.HashMap; 8 | 9 | import javax.crypto.Mac; 10 | import javax.crypto.spec.SecretKeySpec; 11 | 12 | import org.json.simple.JSONObject; 13 | 14 | import com.vdisk.net.session.AppKeyPair; 15 | import com.vdisk.net.session.WeiboAccessToken; 16 | 17 | public class Signature { 18 | 19 | public static final String KEY_MAC = "HmacSHA1"; 20 | 21 | public static final long TIME_STAMP = 1*60*60; 22 | 23 | public static String getSignature(String src, AppKeyPair appKeyPair){ 24 | 25 | String rlt = ""; 26 | try { 27 | BASE64Encoder encoder = new BASE64Encoder(); 28 | rlt = encoder.encode(getHmacSHA1(src, appKeyPair)); 29 | rlt = rlt.substring(5, 15); 30 | } catch (Exception e) { 31 | e.printStackTrace(); 32 | } 33 | return rlt; 34 | } 35 | 36 | @SuppressWarnings("unchecked") 37 | public static String getWeiboHeader(AppKeyPair appKeyPair, WeiboAccessToken weiboToken){ 38 | HashMap data = new HashMap(); 39 | Date date = new Date(); 40 | String seconds = String.valueOf((date.getTime()) / 1000 + TIME_STAMP); 41 | data.put("appkey", appKeyPair.key); 42 | data.put("access_token", weiboToken.mAccessToken); 43 | data.put("expires", seconds); 44 | String src = appKeyPair.key+weiboToken.mAccessToken+seconds; 45 | data.put("sign", getSignature(src, appKeyPair)); 46 | JSONObject jsonObject = new JSONObject(); 47 | jsonObject.putAll(data); 48 | 49 | return jsonObject.toJSONString(); 50 | } 51 | 52 | private static byte[] getHmacSHA1(String src, AppKeyPair appKeyPair) 53 | throws NoSuchAlgorithmException, UnsupportedEncodingException, InvalidKeyException { 54 | Mac mac = Mac.getInstance(KEY_MAC); 55 | SecretKeySpec secret = new SecretKeySpec(appKeyPair.secret.getBytes("UTF-8"), 56 | mac.getAlgorithm()); 57 | mac.init(secret); 58 | return mac.doFinal(src.getBytes()); 59 | } 60 | 61 | 62 | } 63 | -------------------------------------------------------------------------------- /VDiskSdk_Example/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | VDiskSdk_Example 4 | 5 | 6 | 7 | 8 | 9 | com.android.ide.eclipse.adt.ResourceManagerBuilder 10 | 11 | 12 | 13 | 14 | com.android.ide.eclipse.adt.PreCompilerBuilder 15 | 16 | 17 | 18 | 19 | org.eclipse.jdt.core.javabuilder 20 | 21 | 22 | 23 | 24 | com.android.ide.eclipse.adt.ApkBuilder 25 | 26 | 27 | 28 | 29 | 30 | com.android.ide.eclipse.adt.AndroidNature 31 | org.eclipse.jdt.core.javanature 32 | 33 | 34 | -------------------------------------------------------------------------------- /VDiskSdk_Example/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 26 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 42 | 43 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /VDiskSdk_Example/libs/json_simple-1.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CloudSide/VdiskSDK-Android/4bd9d5a1aa9d6f398e81e0b58250e5e93cf641af/VDiskSdk_Example/libs/json_simple-1.1.jar -------------------------------------------------------------------------------- /VDiskSdk_Example/libs/weibosdkcore.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CloudSide/VdiskSDK-Android/4bd9d5a1aa9d6f398e81e0b58250e5e93cf641af/VDiskSdk_Example/libs/weibosdkcore.jar -------------------------------------------------------------------------------- /VDiskSdk_Example/proguard-project.txt: -------------------------------------------------------------------------------- 1 | # To enable ProGuard in your project, edit project.properties 2 | # to define the proguard.config property as described in that file. 3 | # 4 | # Add project specific ProGuard rules here. 5 | # By default, the flags in this file are appended to flags specified 6 | # in ${sdk.dir}/tools/proguard/proguard-android.txt 7 | # You can edit the include path and order by changing the ProGuard 8 | # include property in project.properties. 9 | # 10 | # For more details, see 11 | # http://developer.android.com/guide/developing/tools/proguard.html 12 | 13 | # Add any project specific keep options here: 14 | 15 | # If your project uses WebView with JS, uncomment the following 16 | # and specify the fully qualified class name to the JavaScript interface 17 | # class: 18 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 19 | # public *; 20 | #} 21 | -------------------------------------------------------------------------------- /VDiskSdk_Example/project.properties: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by Android Tools. 2 | # Do not modify this file -- YOUR CHANGES WILL BE ERASED! 3 | # 4 | # This file must be checked in Version Control Systems. 5 | # 6 | # To customize properties used by the Ant build system edit 7 | # "ant.properties", and override values to adapt the script to your 8 | # project structure. 9 | # 10 | # To enable ProGuard to shrink and obfuscate your code, uncomment this (available properties: sdk.dir, user.home): 11 | #proguard.config=${sdk.dir}\tools\proguard\proguard-android.txt:proguard-project.txt 12 | 13 | # Project target. 14 | target=android-14 15 | android.library.reference.1=../VDiskSdk 16 | -------------------------------------------------------------------------------- /VDiskSdk_Example/res/drawable-hdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CloudSide/VdiskSDK-Android/4bd9d5a1aa9d6f398e81e0b58250e5e93cf641af/VDiskSdk_Example/res/drawable-hdpi/ic_launcher.png -------------------------------------------------------------------------------- /VDiskSdk_Example/res/drawable-hdpi/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CloudSide/VdiskSDK-Android/4bd9d5a1aa9d6f398e81e0b58250e5e93cf641af/VDiskSdk_Example/res/drawable-hdpi/icon.png -------------------------------------------------------------------------------- /VDiskSdk_Example/res/drawable-ldpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CloudSide/VdiskSDK-Android/4bd9d5a1aa9d6f398e81e0b58250e5e93cf641af/VDiskSdk_Example/res/drawable-ldpi/ic_launcher.png -------------------------------------------------------------------------------- /VDiskSdk_Example/res/drawable-mdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CloudSide/VdiskSDK-Android/4bd9d5a1aa9d6f398e81e0b58250e5e93cf641af/VDiskSdk_Example/res/drawable-mdpi/ic_launcher.png -------------------------------------------------------------------------------- /VDiskSdk_Example/res/drawable-xhdpi/ic_launcher.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/CloudSide/VdiskSDK-Android/4bd9d5a1aa9d6f398e81e0b58250e5e93cf641af/VDiskSdk_Example/res/drawable-xhdpi/ic_launcher.png -------------------------------------------------------------------------------- /VDiskSdk_Example/res/layout/auth_main.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 |