Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3052] Android: Ti.Filesystem.File.write should return boolean

GitHub Issuen/a
TypeNew Feature
PriorityLow
StatusClosed
ResolutionFixed
Resolution Date2011-04-17T02:00:47.000+0000
Affected Version/sn/a
Fix Version/sRelease 1.7.0, Sprint 2011-11
ComponentsAndroid
Labelsandroid, feature, release-1.7.0, reported-1.6.0, rplist
ReporterDawson Toth
AssigneeDon Thorp
Created2011-04-15T03:35:34.000+0000
Updated2011-04-17T02:00:47.000+0000

Description

Problem

On iOS, the "write" function on a Ti.Filesystem.File returns true or false depending on if the write was successful, or false if it's not possible to write to the file or blob. Android doesn't return anything.

Sample Code

var file = Titanium.Filesystem.createTempFile();
if (file.write('my super cool data') === true) {
   alert('PASS: I wrote to a file! YESSS!');
}
else {
   alert('FAIL: I am sad, for I could not tell you I wrote to the file. Weep weep weep.');
}

Tested On

Titanium SDK version: 1.6.0 (02/02/11 15:22 a02f7db...)
PASSES on iOS Simulator 4.2
FAILS on Android Simulator 2.2

Related Documentation

The docs already state that "write" returns a boolean, most likely because that's what iOS does.
http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Filesystem.File.write-method.html"> http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Fil...

Associated Helpdesk Ticket

http://developer.appcelerator.com/helpdesk/view/70481">http://developer.appcelerator.com/helpdesk/view/70481

Attachments

FileDateSize
app.js2011-04-15T03:35:34.000+00001406

Comments

  1. Dawson Toth 2011-04-15

    Also note that this is causing a RHINO USAGE WARNING. It is definitely caused by trying to pull a value out of file.write('whatever'), as demonstrated here:

    Rhino Usage Warning

       Location: [1,0] app://app.js
       Source: {there isn't anything in here... it's blank in the alert}
       Message: RHINO USAGE WARNING: Missed Context.javaToJS() conversion: Rhino runtime detected object undefined of class org.appcelerator.kroll.KrollProxy$1 where it expected String, Number, Boolean, or Scriptable instance. Please check your code for missing Context.javaToJS() call.
       

    Sample Code

    This is all you need in your app.js. Simple, huh? When the app launches, you should see the warning message.

       Ti.Filesystem.createTempFile().write('chicken') === true;
       

    Trace Level Log

       [INFO] Deployed Playground2 ... Application should be running.
       [TRACE] I/Log ( 387): (main) [0,0] checkpoint, app created.
       [TRACE] I/TiApplication( 387): (main) [297,297] Titanium 1.6.0 (2011/02/02 15:22 02f7db...)
       [TRACE] D/TiApplication( 387): (main) [5,302] Application onCreate
       [TRACE] D/dalvikvm( 387): GC_FOR_MALLOC freed 3471 objects / 332160 bytes in 149ms
       [TRACE] E/TiPlatformHelper( 387): (main) [545,847] renaming ID
       [TRACE] I/Log ( 387): (main) [0,0] checkpoint, on root activity create, savedInstanceState: null
       [TRACE] E/TiRootActivity( 387): (main) [5,5] Instance Count: 0
       [TRACE] D/TiApplication( 387): (main) [148,153] Analytics Event: type=ti.start
       [TRACE] D/TiApplication( 387): event=ti.start
       [TRACE] D/TiApplication( 387): timestamp=2011-02-04T17:49:14.030-0600
       [TRACE] D/TiApplication( 387): mid=8a431ae8-f811-488a-9758-4d15bf980db2
       [TRACE] D/TiApplication( 387): sid=682aa288-3a3c-479f-acdf-bd115fa52b5d
       [TRACE] D/TiApplication( 387): aguid=d85d7f90-1fae-46cf-93e6-6e0a57d6b5f3
       [TRACE] D/TiApplication( 387): isJSON=true
       [TRACE] D/TiApplication( 387): payload={"os":"sdk","tz":-360,"nettype":"MOBILE","deploytype":"development","app_version":"1.0","osver":"2.2","un":"android-build","version":"1.6.0"}
       [TRACE] E/TiApplication( 387): (main) [275,428] APP PROXY: [Ti.App]
       [TRACE] E/ROOT ( 387): (main) [317,745] Leaving TiRootActivity.onCreate
       [TRACE] I/Log ( 387): (main) [0,0] checkpoint, on root activity resume. context = org.appcelerator.titanium.TiContext@44f19ab0
       [TRACE] I/TiRootActivity( 387): (Thread-9) [8,8] eval app.js
       [TRACE] D/KrollContext( 387): (kroll$1) [25,33] Running evaluated script: app://app.js
       [TRACE] W/TiAnalyticsSvc( 387): (Thread-10) [186,219] Analytics Service Started
       [TRACE] I/global ( 387): Default buffer size used in BufferedWriter constructor. It would be better to be explicit if an 8k-char buffer is required.
       [TRACE] D/dalvikvm( 387): GC_FOR_MALLOC freed 5135 objects / 356288 bytes in 312ms
       [TRACE] E/TiContext( 387): (kroll$1) [243,462] Rhino Error: app://app.js:1,0
       [TRACE] E/TiContext( 387): (kroll$1) [342,804] Message: RHINO USAGE WARNING: Missed Context.javaToJS() conversion:
       [TRACE] E/TiContext( 387): Rhino runtime detected object undefined of class org.appcelerator.kroll.KrollProxy$1 where it expected String, Number, Boolean or Scriptable instance. Please check your code for missing Context.javaToJS() call.
       [TRACE] E/TiContext( 387): (kroll$1) [2,806] Source: null
       [TRACE] I/TiAnalyticsSvc( 387): (Thread-10) [956,1762] Sending 1 analytics events.
       [TRACE] I/ActivityManager( 60): Displayed activity com.dawson.playground2/.Playground2Activity: 6075 ms (total 6075 ms)
       [TRACE] D/dalvikvm( 387): GC_FOR_MALLOC freed 5968 objects / 357208 bytes in 101ms
       [TRACE] D/dalvikvm( 387): GC_FOR_MALLOC freed 504 objects / 25168 bytes in 93ms
       [TRACE] W/TiAnalyticsSvc( 387): (Thread-10) [4018,5780] Stopping Analytics Service
       [TRACE] D/dalvikvm( 248): GC_EXPLICIT freed 218 objects / 14688 bytes in 87ms
       [TRACE] D/dalvikvm( 258): GC_EXPLICIT freed 31 objects / 1496 bytes in 91ms
       [TRACE] D/dalvikvm( 132): GC_EXPLICIT freed 200 objects / 10696 bytes in 66ms
       

    Tested On

    Titanium SDK version: 1.6.0 (02/02/11 15:22 a02f7db...)
    Occurs on Android Simulator 2.2

  2. Opie Cyrus 2011-04-15

    (from [2b9fd7dae1c45c8bf55b0d930659494c05ec3ebc]) [#3052 state:fixed-in-qa] change File write to return a boolean value

    changed write method on file object to return a boolean value indicating whether the write was successful or not
    https://github.com/appcelerator/titanium_mobile/commit/2b9fd7dae1c45c8bf55b0d930659494c05ec3ebc"> https://github.com/appcelerator/titanium_mobile/commit/2b9fd7dae1c4...

  3. Opie Cyrus 2011-04-15

    Please verify fix with the attached app.s. When running, you should see:

    03-16 20:01:48.546: INFO/ALERT(437): (kroll$1: app://app.js) [2717,13782] PASS: I wrote to a file! YESSS!

  4. Natalie Huynh 2011-04-15

    Tested with Titanium SDK version: 1.7.0 (03/16/11 13:28 2b9fd7d) on
    Nexus S 2.3.2
    I/ALERT ( 1071): (kroll$3: app://app.js) [323,396] PASS: I wrote to a file! YESSS!
    Emulator 2.1
    [TRACE] I/ALERT ( 275): (kroll$1: app://app.js) [430,772] PASS: I wrote to a file! YESSS!

JSON Source