Status Update
Comments
oa...@comcast.net <oa...@comcast.net> #2
// Write the file
OutputStream outputStream = getContentResolver().openOutputStream(currentUri);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(outputStream );
Actually the problem seems to be with ParcelFileDescriptor.AutoCloseOutputStream . I can get the code above to work fine if I don't use getContentResolver().openOutputStream(currentUri) , which returns a ParcelFileDescriptor.AutoCloseOutputStream .
If I use:
// Write the file
FileOutputStream fos = new FileOutputStream(new File(getFilesDir(), "out.txt"));
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fos);
it WORKS correctly on any API level.
But as I am using external storage and have to use the ContentProvider given when I get access to the storage via a chooser, all I have to deal with is a content Uri and not a file name nor file handle. I have to go through the getContentResolver methods.
Note that:
// Write the file
ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(currentUri, "w");
FileDescriptor fd = pfd.getFileDescriptor();
FileOutputStream fos = new FileOutputStream(fd);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fos);
Does not work either. Somewhere in the ParcelFile system things are going wrong.
ja...@google.com <ja...@google.com> #3
Thank you for reporting this issue. We just need a few things for us to further investigate this issue:
Please fill out each question and comment, thank you.
-
Have you observed this bug on Pixel devices as well?
-
Android Build Version (go to Settings > About Device > Build Number (hold down to copy))
-
Android Device Model:
-
If possible, capture the issue in a screen recording (desktop and/or phone capture).
-
Upload the full bug report file after the issue has occurred. Steps followed here:
https://developer.android.com/studio/debug/bug-report -
Please provide a simple sample project (exported zip Android Studio file) that reproduces the issue. This gives us the closest test environment to yours and allows us to inspect the code/structure used which will help analyze your issue.
-
Steps to reproduce issue specific to the provided sample project: [Be as specific as possible]
- 1
- 2
- 3
-
Expected Results:
-
Observed Results:
Note: Please upload to google drive and share the folder to
The more information we have, the more accurately our product and engineering team can solve the issue. Thank you so much for your time and for your cooperation.
oa...@comcast.net <oa...@comcast.net> #4
<Android Build Version ?> My friend's phone is on Android 10. Emulators with API 29 and API 30 had the problem. My own phone and API 26 and API 28 emulators did not. Project compile SDK is API 30, tools version is 29.0.3.
<Android Device Model ?> My friend's device is a Samsung Galaxy S-10, model SM-G973U.
<If possible, capture the issue in a screen recording (desktop and/or phone capture).> Irrelevant.
<Upload the full bug report file after the issue has occurred> Irrelevant since this was run via emulator.
<Steps to reproduce issue specific to the provided sample project>
1. Copy testCopy.csv from the assets directory onto the phone somewhere or into an API 29 or greater emulator.
2. Start the app , click and choose menu "Open Table..."
3. Choose file "testCopy.csv" with the file chooser.
4. Check the current contents of testCopy.csv now. It is corrupted.
<Expected Results>
delimiter ,
debug true
Name,Pet,Email,Phone,Audio,Notes,Web
125,100,160,100,100,100,150
12
40
fullname,image,email,phone,audio,note,url
arreter[1],Clipboard01.jpg,lriehl@comcast.net,360-742-3631,sound1407360340825148972.aac,note1.txt,<Name>#
Audrey Oakes,Clipboard04.jpg,oakesa@comcast.net,253-639-3558,sound421577012195097098.aac,note3.html#58,Amazon#
Norm Oakes,Clipboard04.jpg,oakesn@comcast.net,253-639-3558,sound421577012195097098.aac,note2.html#3,
<Observed Results>
delimiter ,
debug true
Name,Pet,Email,Phone,Audio,Notes,Web
125,100,160,100,100,100,150
12
40
fullname,image,email,phone,audio,note,url
arreter[1],Clipboard01.jpg,lriehl@comcast.net,360-742-3631,sound1407360340825148972.aac,note1.txt,<Name>#
Audrey Oakes,Clipboard04.jpg,oakesa@comcast.net,253-639-3558,sound421577012195097098.aac,note3.html#58,Amazon#
Norm Oakes,Clipboard04.jpg,oakesn@comcast.net,253-639-3558,sound421577012195097098.aac,note2.html#3,
The error is that "
Sample project is at
ja...@google.com <ja...@google.com> #5
Thank you for providing your update. We just need a few things for us to further investigate this issue:
-
When attempting to reproduce the issue following your provided steps, the view is empty after selecting "Open table..." and choosing the provided .csv - where exactly are you observing the output text from the csv file? Thanks for your clarity.
-
Pixel 4 Emulator API 30: debug build variant
oa...@comcast.net <oa...@comcast.net> #6
4. Check the current contents of testCopy.csv now. It is corrupted.
oa...@comcast.net <oa...@comcast.net> #7
ja...@google.com <ja...@google.com> #8
Thank you so much for the updates:
- Just to confirm, you are taking the csv file, that is now within the phone, and transferring it outside the phone to view it after having opened it within your sample app using "Open table..."
oa...@comcast.net <oa...@comcast.net> #9
ja...@google.com <ja...@google.com> #10
Thank you for reporting this issue. We’ve shared this with our product and engineering teams and will continue to provide updates as more information becomes available.
oa...@comcast.net <oa...@comcast.net> #11
Project uploaded to:
Same test instructions as previous uploaded project.
<Steps to reproduce issue specific to the provided sample project>
1. Copy testCopy.csv from the assets directory onto the phone somewhere or into an API 29 or greater emulator.
2. Start the app , click and choose menu "Open Table..."
3. Choose file "testCopy.csv" with the file chooser.
4. Check the current contents of testCopy.csv now. It is corrupted.
<Expected Results>
delimiter ,
debug true
Name,Pet,Email,Phone,Audio,Notes,Web
125,100,160,100,100,100,150
12
40
fullname,image,email,phone,audio,note,url
arreter[1],Clipboard01.jpg,lriehl@comcast.net,360-742-3631,sound1407360340825148972.aac,note1.txt,<Name>#
Audrey Oakes,Clipboard04.jpg,oakesa@comcast.net,253-639-3558,sound421577012195097098.aac,note3.html#58,Amazon#
Norm Oakes,Clipboard04.jpg,oakesn@comcast.net,253-639-3558,sound421577012195097098.aac,note2.html#3,
<Observed Results>
��limiter , <--- Weird !! The file should ONLY contain these first two characters !!
debug true
Name,Pet,Email,Phone,Audio,Notes,Web
125,100,160,100,100,100,150
12
40
fullname,image,email,phone,audio,note,url
arreter[1],Clipboard01.jpg,lriehl@comcast.net,360-742-3631,sound1407360340825148972.aac,note1.txt,<Name>#
Audrey Oakes,Clipboard04.jpg,oakesa@comcast.net,253-639-3558,sound421577012195097098.aac,note3.html#58,Amazon#
Norm Oakes,Clipboard04.jpg,oakesn@comcast.net,253-639-3558,sound421577012195097098.aac,note2.html#3,
As far as I understand, opening a stream in "w" mode should always clear the contents of an existing file.
ja...@google.com <ja...@google.com> #12
Thanks again for reporting this issue. Our product and engineering team has responded with:
Can you please be more specific why you think OutputStreamWriter has a bug?
oa...@comcast.net <oa...@comcast.net> #13
From my last example is should have been abundantly clear that my output file was being OVERWRITTEN. I basically accidentally came across documentation in ContentProvider.openFile(Uri uri, String mode) where is says "String: Access mode for the file. May be "r" for read-only access, "rw" for read and write access, or "rwt" for read and write access that truncates any existing file."
I must say that is EXACTLY OPPOSITE from any programming language I know of ! In those languages "w" implies file truncation, "wa" or "w+" means append. Even in Java the default mode for writing files is to truncate. So the fix to my examples is to open my output file in "wt" mode.
The expected results of my last example should have triggered a thought about file overwriting from my comment of "weird" :
��limiter , <--- Weird !! The file should ONLY contain these first two characters !!
Why anyone would want to overwrite their output file is beyond me and apparently other language authors.
I am sorry I took up your time with a false bug but your team also cost me a lot of time and anguish by not pointing out an obvious usage error I was making. By giving multiple examples I was trying to show you how I did things so you could maybe spot a usage error.
Having a CS degree and programmed 35 years professionally, I am not impressed with Google. And I fielded bug reports all those years as well.
ja...@google.com <ja...@google.com>
an...@steadfastinnovation.com <an...@steadfastinnovation.com> #14
I just ran into this issue as well. According to "w"
mode no longer truncating a file, either in the ContentResolver
and related documentation. So it's unclear if this was an intended change or if it's a bug.
I have also reproduced your findings that changing the mode to "wt"
fixes the issue. However, "wt"
is not one of the modes listed by ContentResolver.openOutputStream
ContentProvider
implementation. According to "wt"
and requires that you use "rwt"
. My concern with this is that we don't need "r"
permission and is something else going to fail because we request it...
an...@steadfastinnovation.com <an...@steadfastinnovation.com> #15
I filed
Description
InputStream myInput = getContentResolver().openInputStream(currentUri);
InputStreamReader isr1 = new InputStreamReader(myInput);
isr = new BufferedReader(isr1);
StringBuffer vals = new StringBuffer();
String str = isr.readLine();
while(str != null)
{
vals.append(str).append("\n");
str = isr.readLine();
}
if (myInput != null)
myInput.close();
// Write the file
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(os);
outputStreamWriter.write(vals.toString());
os.flush(); // I was told this was required. Problem occurs w or w/o this line.
outputStreamWriter.close();
Input file:
delimiter ,
debug true
Name,Pet,Email,Phone,Audio,Notes,Web
125,100,160,100,100,100,150
12
40
fullname,image,email,phone,audio,note,url
arreter[1],Clipboard01.jpg,lriehl@comcast.net,360-742-3631,sound1407360340825148972.aac,note1.txt,<Name>#
Audrey Oakes,Clipboard04.jpg,oakesa@comcast.net,253-639-3558,sound421577012195097098.aac,note3.html#58,Amazon#
Norm Oakes,Clipboard04.jpg,oakesn@comcast.net,253-639-3558,sound421577012195097098.aac,note2.html#3,
Output:
delimiter ,
debug true
Name,Pet,Email,Phone,Audio,Notes,Web
125,100,160,100,100,100,150
12
40
fullname,image,email,phone,audio,note,url
arreter[1],Clipboard01.jpg,lriehl@comcast.net,360-742-3631,sound1407360340825148972.aac,note1.txt,<Name>#
Audrey Oakes,Clipboard04.jpg,oakesa@comcast.net,253-639-3558,sound421577012195097098.aac,note3.html#58,Amazon#
Norm Oakes,Clipboard04.jpg,oakesn@comcast.net,253-639-3558,sound421577012195097098.aac,note2.html#3,
The "
I really want to use OutputStreamWriter with a CharSet of ISO-8859-1.
This happens in API 29 and higher. This code works fine with API 29 and API 26.