History log of /libcore/luni/src/main/java/java/io/RandomAccessFile.java
Revision Date Author Comments
0b736ebc4efef64f2db1999aea90297ad8196146 20-May-2011 Elliott Hughes <enh@google.com> Move the stuff to bridge between io/net/nio semantics and POSIX semantics.

IoUtils should be more generally useful.

Change-Id: I5665f2a94d226ada3077a30045549a53cc741cf0
462bdac45c10f43d88d8f07f6994e272a27c14a2 30-Mar-2011 Elliott Hughes <enh@google.com> Add close(2).

This is sufficient for non-socket fds, but may need to change to support the
asynchronous socket close monitor. (Hopefully not; I'd rather lift that into
Java.)

I've also changed the semantics of IoUtils.close to match those desired by
all callers: ignore null/invalid FileDescriptors.

Bug: 3107501
Change-Id: Iad5c31c8f0f34d2a5ab1ed4581509b46af28bd1f
8b15dcc5890963edad4dfcf558cc16027c7985e5 29-Mar-2011 Elliott Hughes <enh@google.com> Add sendfile(2).

This patch marks the end of OSFileSystem.

Having to support a Java "long*" for sendfile(2) gave me an opportunity to go
back and improve my ioctl(2) to use a corresponding "int*" equivalent, instead
of its previous special-case hack.

Bug: 3107501
Change-Id: I9fde4777700552263fab4fe9aeb556174163e3dc
78c7cc547101002b9f9043cf3845970719d1bda8 26-Mar-2011 Elliott Hughes <enh@google.com> Add write(2).

Note that this is a functional change, because the old code was wrong: it
assumed that short writes don't happen. I thought we'd (I'd) cleaned this
up just recently, but it looks like I must have only gone through the network
code. Embarrassing.

This also cleans up the previous read change a bit, factoring out a bit more
duplication, and taking advantage of the fact that we now get decent
exceptions thrown from invalid FileDescriptors (meaning we can remove explicit
checks).

Bug: 3107501
Change-Id: I8bd5324836c9d151dceaef5b84ec523a67391b64
da5f38a51f56f38070e6efc1bdf9176004dd828d 26-Mar-2011 Elliott Hughes <enh@google.com> Fix build (javadoc).

Change-Id: I7b109098bb367a2583d11bf41f5b9993e5009e42
26c7025a7a919044771fb89031161bd26fe03032 26-Mar-2011 Elliott Hughes <enh@google.com> Add read(2).

For both byte[]s and ByteBuffers.

Bug: 3107501
Change-Id: I93b781069ade4507371c8fe8c5fda0163fbb2dbb
0ac77ac8e915bff1a863e371f9b363033f9cf759 23-Mar-2011 Elliott Hughes <enh@google.com> Add open(2).

Bug: 3107501
Change-Id: I404030b4c678862465d04f723a6a324663e0af25
dedaccdfa07c370a58cba08b096133ad9eec0ec3 18-Mar-2011 Elliott Hughes <enh@google.com> Add lseek(2).

Bug: 3107501
Change-Id: Ie27e2ae1c7d37de5f02b1d81ee2005182339f881
f5333fd2094bdac4d6506177b1964b79afa64d77 18-Mar-2011 Elliott Hughes <enh@google.com> Add ftruncate(2).

The claim that "the port library" modifies the file offset appears to only ever
have been true of Harmony's Win32 implementation. Certainly, this is not the
behavior of ftruncate(2), so we can lose the cruft.

Bug: 3107501
Change-Id: I35092fd986296b78c4847c7215765f9997339f37
47cb338d43f75dd998b29caaaa9446c5705217d1 18-Mar-2011 Elliott Hughes <enh@google.com> Add fstat(2), lstat(2), and stat(2).

Bug: 3107501
Change-Id: Ic36f9ffd03446d6e0189470f42abdadde57327df
52724d3ebd4ccaaa4b9f5576e329d4272cde8ea9 17-Mar-2011 Elliott Hughes <enh@google.com> Add fsync(2) and fdatasync(2).

Interesting parts to this change:
* first BlockGuard support (and general delegation support).
* first rethrowing of ErrnoException as IOException.
* switching FileChannelImpl from int to FileDescriptor.

The special case in FileDescriptor.sync has been removed. Testing with the RI
showed that it doesn't treat syncing a FileDescriptor that corresponds to a
socket as a special case --- it throws SyncFailedException just like normal.

Bug: 3107501
Change-Id: I99faf120bd802aec0397a79772ed38c5e1542fed
cdf7a1f942469221bcfd63d9cdf71851b011eaf0 16-Mar-2011 Elliott Hughes <enh@google.com> Expose POSIX constants.

And use them, too. This patch is a little confusing because we already had
constants in Java that were using the POSIX names but that didn't actually
correspond to the constants whose names they'd stolen. Ugh.

Bug: 3107501
Change-Id: Ib64a109c9340b0ecdf80bec91074206c001f455a
f934c3d2c8dd9e6bc5299cef41adace2a671637d 15-Mar-2011 Elliott Hughes <enh@google.com> Make OSMemory the semi-supported libcore.io.Memory.

Looks like we're not going to bother with a separate libcore.os package,
when libcore.io will do.

Change-Id: I2806c59349ed4b6410d768c4207c384ced973c54
6186821cb13f4ac7ff50950c813394367e021eae 08-Feb-2011 Jesse Wilson <jessewilson@google.com> Move libcore.base classes to libcore.util and libcore.io.

Change-Id: I2340a9dbad3561fa681a8ab47d4f406e72c913e3
ad41624e761bcf1af9c8008eb45187fc13983717 07-Jan-2011 Elliott Hughes <enh@google.com> Retire SecurityManager.

This change removes all the code that was calling getSecurityManager, and
removes all use of AccessController.doPrivileged. It also changes the
implementation of AccessController so it doesn't actually do anything; it's
only there for source-level compatibility.

Bug: 2585285
Change-Id: I1f0295a4f12bce0316d8073011d8593fee116f71
a1603838fe9e865575c87982e32c6343740e464c 11-Dec-2010 Elliott Hughes <enh@google.com> Lots more bounds-checking/exception-throwing consistency.

Overflow-safe checks all round, plus better detail messages. This isn't
quite everything, but it's a large chunk of the work. Most notably, this
is all of io and nio.

There are numerous changes of exception priority here, and the harmony
tests noticed a subset of them in the nio code. I've modified our checked-out
copy of the tests to accept any of the throwable exceptions.

Change-Id: Id185f1228fb9a1d5fc9494e78375b5623fb0fe14
0eb70e31581a977afa5df3292d1c96e42e548821 28-Oct-2010 Elliott Hughes <enh@google.com> Optimize DataInputStream and a few friends.

Also ensure that we're doing a correct readFully when reading
shorts/ints/longs.

Bug: 3032515
Change-Id: I39e6f926537f5d55063db8fc1c5a1b4b794746d4
c6c6c5d5176f739e0ceecedbdf277513bf4854b1 28-Oct-2010 Elliott Hughes <enh@google.com> Optimize DataOutputStream and RandomAccessFile.

Use OSMemory's byte[] peek/poke routines, and reuse a single buffer in
RandomAccessFile, as DataOutputStream was already doing.

Bug: 3032515
Change-Id: I50f34be9a9e126965759a221b21b05baf4b56083
9559e748729ef1deb6400f31d0407543cbff3566 21-Oct-2010 Elliott Hughes <enh@google.com> Improve our modified UTF-8 implementation.

I was out looking for customers for the new OSMemory peek/poke for byte[]s,
and ran into this mess. I also noticed we didn't have any real tests for
DataOutputStream. This patch rewrites DataOuputStream and ObjectOutputStream
to be simpler and cleaner, pulls modified UTF-8 encoding support out into
ModifiedUtf8 where it belongs, and adds a new special ICU-avoiding case for
String.getBytes("UTF-16BE"). And adds tests.

Bug: 3032515
Change-Id: I618c8b1bda13138feed7710e29aee0f96f2e9b95
12f2d8e2760b78c673b7a187b9062b3938a03147 12-Oct-2010 Brian Carlstrom <bdc@google.com> Revised CloseGuard usage pattern

- CloseGuard.get() instants are now "unopened"
- In constructor cases, guard.open("...") is now at the end
- In metod cases, guard.open("...") is now after resource acquisition
- guard null pointer checks in finalizers in case constructor threw exception

Bug: 2645458
Change-Id: Ieb874a8c33b347768a9fa7437b3dd16f3d56d886
765c2139fde183fc60e6fcb22a6b75378d7dbcb5 08-Oct-2010 Jesse Wilson <jessewilson@google.com> Drop a proper finalizer in RandomAccessFile to catch resource leaks.

Submitted to dalvik-dev as https://android-git.corp.google.com/g/72685
http://b/3015023

Change-Id: I30635aab91774f5eaecd354e8418ba6401705757
fbe7f04ba384cb7ea7aca7d291b2596622ff1b0e 07-Oct-2010 Jesse Wilson <jessewilson@google.com> Drop a proper finalizer in RandomAccessFile to catch resource leaks.

http://b/3015023
Change-Id: Ic938c82d3353a2231619f2bd87e4480a2b57c622
6662feeaf43812ff4336150a473bce06fc802b79 23-Sep-2010 Elliott Hughes <enh@google.com> Improve RandomAccessFile documentation.

Change-Id: I74ae5b018f2c140e97b516576ef582d213a1b7cc
ac7d2424dfd5267434d18d06174d1b481d3b51a7 22-Sep-2010 Jesse Wilson <jessewilson@google.com> Fix setLength() to adjust pointer.

See http://b/2224985

Change-Id: Ie8b7a7a455fdbde051dea15f8d3e4dc6bf8f6fba
ae704b984c10a63883cc366e823d53902d6ac7a9 21-Sep-2010 Elliott Hughes <enh@google.com> Minor tidy-up.

The nio implementation is still a bit of a mess because Java doesn't have any
kind of "module" concept, nor "friend". But this makes it a little less untidy,
and makes the deliberate access control subversions a little more explicit, and
makes various things less accessible than they were.

Change-Id: I514b1e24000b91f86b768ed408fedae115dc3080
171dc20afe5071d5cbfad7103903bfa2c1f8d00f 02-Sep-2010 Elliott Hughes <enh@google.com> Use idiomatic Java "type[] id" syntax instead of "type id[]".

I've left xalan and the other xml filth alone, as usual.

Change-Id: I6be274501fff73e67ca6b3c872704988e0e30486
3db0d1b07a79c3c871b0aa0929674adae3081b4f 28-Aug-2010 Elliott Hughes <enh@google.com> Remove the accessors hiding our IFileSystem and INetworkSystem.

These accessors aren't buying us anything, are costing us something, and have
encouraged caching of instances in fields all over the place. Lose all that
cruft.

I think we all agree that we want to merge IFileSystem and INetworkSystem at
some point, but I'll do that some other day.

Change-Id: I07696ec9650d0395ec31a71a74300e818a3fed91
7365de1056414750d0a7d1fdd26025fd247f0d04 12-Aug-2010 Jesse Wilson <jessewilson@google.com> Sorting imports.

Change-Id: I8347bc625480a1c37a1ed9976193ddfedeb00bbc
99a89dd6f0a0e1396aa9b3feebf15ea31f703d3a 04-Aug-2010 Elliott Hughes <enh@google.com> Rewrite the nio Pipe to use a Unix pipe behind the scenes.

We were using an AF_INET or AF_INET6 socket to implement the nio Pipe, which
was causing trouble for people on systems where IPv6 wasn't working yet.

This patch switches over to pipe(2). My first implementation used socketpair(2)
and retained the SocketChannelImpls, but it still seemed a bit off to be asking
for a full-duplex pipe to implement a unidirectional channel, and it required
hacks in the networking code to cope with the AF_LOCAL family, and in the
BlockGuard for the isLingeringSocket test.

This implementation uses pipe(2) and FileChannelImpl. It breaks a few tests, but
the tests are wrong, and it actually brings us closer to the RI's behavior of
throwing IOException "broken pipe" when writing to a broken pipe.

Rather than keep throwing junk into the FileSystem/NetworkSystem classes, and
resolving the question of which of those setNonBlocking belonged in (answer:
neither; this is a false Windows-style dichotomy that isn't helpful here), I've
added a new IoUtils with a few generally useful methods. The remainder of this
patch switches over existing code. We could probably make
FileDescriptor.descriptor private now I've exposed accessors, but this change
is large enough already...

Bug: 2735373
Bug: http://code.google.com/p/android/issues/detail?id=9431
Change-Id: I6b6d1e50bdddd435e71c31105a73c9d4fd135d7e
aaacdb095b10293286adbfd94af2fd83b8dae3a8 22-Jul-2010 Elliott Hughes <enh@google.com> Remove File's cached UTF-8 byte[].

This doesn't really improve File.getCanonicalPath and its helpers much, but it
improves everything else, and feels like a step in the right direction.

Benchmarking shows only a tiny difference in the uncommon case of a reused
File, and a significant increase in performance in the more likely case of
a single-use File.

Before:

benchmark us
Exists 26.14
ExistsReuse 5.08

After:

benchmark us
Exists 13.90
ExistsReuse 5.23

Bug: 2281992
Change-Id: Ibc6fd2581983ae8a57bf4b7f49196c76ad41169e
e810d3b49631329b11440aa5b7a54db181d42ed1 15-Jun-2010 Elliott Hughes <enh@google.com> More charset-related cleanup/optimization.

This patch adds a Charsets class that lets us avoid a hash lookup and an extra
level of method call indirection when calling String.getBytes or "new String"
for a well-known guaranteed charset. It also fixes callers to take advantage.

This also adds a special case to "new String" for the UTF-8 charset to avoid
needless duplication if we guessed the correct buffer size (which we will for
input that happens to be US-ASCII too).

The ModifiedUtf8 class gives a more meaningful name for Utils.convertUTF8WithBuf.

This also removes a dead link and un-tinyurl'ed another.

Change-Id: I02712f53dee16feb3b1db2c14536dc055126cd04
c903e6720bbbf6540c29f141bd2fa559813ea20a 08-Jun-2010 Elliott Hughes <enh@google.com> Improve Charset.forName/"new String" performance.

Lookup String's default charset once at class initialization. Stop
creating a new empty char[] every time we create an empty string. Fix
the documentation not to lie about using ISO-8859-1 in all kinds of
places we don't (and where the RI doesn't specify that we should).
Fix the performance of the String(byte[]...String) and String(byte[]...Charset)
constructors to be equivalent rather than wildly different (and not in the way
anyone would reasonably expect). Canonicalize the requested charset's name
so that we can uniformly optimize all aliases of those charsets we
special-case, rather than just those few aliases we used to hard-code.

Tidy up the String.getBytes methods in preparation for optimization (in a later
patch).

Fix the performance of Charset.forName to be amortized constant time regardless
of what name is used, in recognition of the fact that Unicode TR#22 section 1.4
means that there are a potentially infinite number of valid pseudo-aliases for
any charset (at least two of which are relatively common in libcore itself, so
I'd imagine plenty are used in the wild too). Some slight synchronized-related
tidying, and more reuse of public API (because one day I'd like to improve the
locking situation deeper down in this code).

In HistoricalNameUtil.java, remove ugliness.

In File.java, use "new String" rather than junk from Util.

In RandomAccessFile.java, reuse convertUTF8WithBuf instead of the otherwise
unused convertFromUTF8 convenience method.

In Util.java, remove now-dead code and comment some code that looks like it
should be killed but is actually unique and necessary. (I'll probably move
this into an intention-revealing class in my next patch. "Util", FFS! "UTF8",
FFS!)

Also add a couple of tests to StringTest.java to show that my improved String
documentation is true, and that some bogus code that I removed was indeed
bogus.

Change-Id: I746f990172c51c30aa5f5037346644552a224841
b1396870f92135aa140bd2b86221768dea5bc11d 25-May-2010 Elliott Hughes <enh@google.com> Remove the luni localized exception messages.

Also fix a bug I introduced in KXmlSerializer: s.isEmpty() is not
equivalent to "".equals(s) if s is allowed to be null.

Bug: 1251121
Change-Id: I41a0a98ffb49f214041c9110f824d327af5c34e8
f33eae7e84eb6d3b0f4e86b59605bb3de73009f3 13-May-2010 Elliott Hughes <enh@google.com> Remove all trailing whitespace from the dalvik team-maintained parts of libcore.

Gentlemen, you may now set your editors to "strip trailing whitespace"...

Change-Id: I85b2f6c80e5fbef1af6cab11789790b078c11b1b
fd6bb3510c2f94d636f3572dcf5f7f4dcd1a2726 13-May-2010 Elliott Hughes <enh@google.com> Remove //$NON-NLS-\d$ cruft.

Mostly done by perl(1), with manual cleanup of the few misspelled instances.
This makes our trailing whitespace slightly worse, but I'll fix all that with
a follow-on change.

Change-Id: I0b4ca98819be6f9519c4ba980d759bd1ee1a0303
a008cf079f1cb812ec42a4fcc941fe170cc9b40d 13-May-2010 Elliott Hughes <enh@google.com> Minor file system changes.

Use fstat(2) instead of three seek(2)s to get the length of a file.

Java's readv should return -1 at EOF rather than 0.

The size() == 0 check in FileChannelImpl was (apparently) bogus.

(These changes are basically the same as harmony changes, and fix existing
harmony tests, so no new tests.)

Change-Id: I302611f777e91571b95654e03d0a3a41e1f97968
93a4b2a6cc35a72aa5a58027025f3e18c0ec2e64 05-Dec-2009 Elliott Hughes <enh@google.com> More java.io.File cleanup.

Two changes:

1. Change the createNewFile JNI to match the Java interface, so we can lose the
glue. (Also make the Java/JNI names match, and sort the table of native method
names alphabetically.)

2. Fix the caching of the path byte sequence so we're caching the exact byte
sequence we want to hand to JNI. Also switch to caching the byte[] at
construction time, rather than hiding it behind an accessor.

There's a deliberate functional change here too: previously we were inconsistent
about which encoding was in use. Sometimes it was explicitly UTF-8, other times
the default platform encoding (which happens to be UTF-8 on Android). Now we
always use UTF-8. (But note that the File.list methods, which I haven't got to
yet, still return a mix of UTF-8 and platform-encoded strings.)

Bug: 2281992
4fefecee9d4a5d2a4510f516b4015607b19e8d09 13-Nov-2009 Jean-Baptiste Queru <jbq@google.com> eclair snapshot
f5597e626ecf7949d249dea08c1a2964d890ec11 25-Jul-2009 Jesse Wilson <jessewilson@google.com> Integrate luni module (but not tests) to Harmony r772995.

Notable changes
- Stripped "@since Android 1.0" from many files. Most files
are now 100% the same in Dalvik and Harmony.
- AbstractStringBuilder.reverse() supports surrogates
- AbstractStringBuilder shares less to waste less memory
- Bitset optimized
- BufferedInputStream changed to support unsynchronized close()
- BufferedOutputStream does flushInternal
- BufferedReader supports EBCDIC NEL
- Collections.synchronizedList().indexOf() does a copy for more concurrency
- Classes in nio module changed: DatagramChannelImpl, SocketChannelImpl
and ServerSocketChannelImpl (these depend on internal APIs changed in
this update)
- DataInputStream/DataOutputStream now use a small buffer to limit the
number of times the underlying stream is accessed
- Date now has a minutes offset, more efficient toString()
- ExposedByteArrayInputStream: new internal class
- DeleteOnExit moved to top-level class
- FileDescriptor.isValid() now non-native
- Float, Double lessThan optimized (fix for compare(-0.0F, 0.0F) still pending)
- FileURLConnection now guesses content types from streams
- HashMap iterator changes
- Hashtable iterator changes
- INetworkSystem
- removes bind2(), createMulticastSocket, sendStream(),
- renames createSocket to createStreamSocket
- JarURLConnection rewritten
- LinkedHashMap: new iterator
- Locale, Currency, TimeZone: now use ICU in Harmony, plain Java in Dalvik
- ObjectInputStream: Accessor objects in Harmony, direct native in Dalvik
- ProxyClassFile - many changes
- String - optimized ascii for toLowerCase, toUpperCase, compare
- Timer - rewritten
- TreeMap - rewritten
- URLClassLoader - new
- URLConnection - new guessContentTypeFromStream(), uses org.apache.harmony.awt.www.content
to lookup content type handlers
adc854b798c1cfe3bfd4c27d68d5cee38ca617da 04-Mar-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //depot/cupcake/@135843
1c0fed63c71ddb230f3b304aac12caffbedf2f21 04-Mar-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //depot/cupcake/@135843
a0881d052ee72e3f7e773374e9b1aa75fbd6be4c 10-Jan-2009 The Android Open Source Project <initial-contribution@android.com> auto import from //branches/cupcake/...@125939
dd828f42a5c83b4270d4fbf6fce2da1878f1e84a 18-Dec-2008 The Android Open Source Project <initial-contribution@android.com> Code drop from //branches/cupcake/...@124589
fdb2704414a9ed92394ada0d1395e4db86889465 21-Oct-2008 The Android Open Source Project <initial-contribution@android.com> Initial Contribution