History log of /libcore/luni/src/main/java/libcore/io/IoUtils.java
Revision Date Author Comments
30c669166d86d0bd133edfb67909665fb41d29b6 16-Jan-2015 Narayan Kamath <narayan@google.com> Remove fcntlLong, use fcntlInt for F_SETFD instead.

fcntlLong works too, but only because of the syscall conventions
happen to place the lower 32 bits of our jlong in the right register.

This change also gets rid of fcntlLong because there aren't any
documented fcntl calls that take a 64 bit integer argument.

Change-Id: I8d187d5b906195fc663675a07a5f116dcd210d16
7c22337691326a03386e42a32becbeb2c2dc7f06 14-Nov-2014 Narayan Kamath <narayan@google.com> Set random seeds post fork.

Gets rid of static Random objects from various classes and
makes them use Math.random instead. Also add hidden APIs to
set the random seed post fork (where we're single threaded).

This has the nice side effect of fixing a performance bug
related to linpack (11388705) where threads were serializing
on Math.class while calling Math.random.

bug: https://code.google.com/p/android/issues/detail?id=79143
bug: 11388705
Change-Id: Ide3a7d17fe855a8086601348be87a890e4c42ab4
41d8acb87dd1b722cf54e4c64e72c6a13688a849 29-Apr-2014 Elliott Hughes <enh@google.com> Move ErrnoException into android.system.

Change-Id: Id22bebb6aadeff0729f430fce3f702d974a23efc
a2fac5bc3fc5c182e738aa4f3fcc64bb38dfbf5f 29-Apr-2014 Elliott Hughes <enh@google.com> Move StructStat and StructStatVfs now all the callers have switched over.

Change-Id: Ia599ea8d65645eb97c6944743e0a9510991c0607
5d930cadc8f62aee5f18e7921296fe66a54f18ab 24-Apr-2014 Elliott Hughes <enh@google.com> Groundwork towards making the Libcore.os functionality public.

Change-Id: Ie700aa16d91fba53fc5eb2555829cb74d84b12ad
c7b35cdea3d660c8d4b77e11fa0ef19f6ca17db9 30-Oct-2013 Narayan Kamath <narayan@google.com> Remove UnsafeByteSequence.

Replace it with a smaller, less general class for reading
the contents of a file into a byte array or a string.

Remove the need for an additional buffer and instead read
the contents of the file directly into a buffer owned by
FileReader. Optimise for the case where the length
of the file is known.

This imposes the additional restriction on callers that the
path of the file they're reading is an absolute path. I've
checked that all callers obey that currently.

(Cherry picked from b0674a77ed67e30f2510064b89151002d7f2eb2a)

Bug: b/11411129
Change-Id: Ic020a45051416f2de9a2f78bd5f99a21feff17df
b0674a77ed67e30f2510064b89151002d7f2eb2a 30-Oct-2013 Narayan Kamath <narayan@google.com> Remove UnsafeByteSequence.

Replace it with a smaller, less general class for reading
the contents of a file into a byte array or a string.

Remove the need for an additional buffer and instead read
the contents of the file directly into a buffer owned by
FileReader. Optimise for the case where the length
of the file is known.

This imposes the additional restriction on callers that the
path of the file they're reading is an absolute path. I've
checked that all callers obey that currently.

Change-Id: Ic020a45051416f2de9a2f78bd5f99a21feff17df
2a6f23ff8690ac2f025588a360547ce96cde0943 29-Jun-2013 Elliott Hughes <enh@google.com> Add java.nio.charsets.StandardCharsets.

Bug: 3484927
Change-Id: I5820267491b850b8fcc696fa48962710de123009
99b4489d0555c6e0e5df941cbfad4cf250c8f0b8 07-Jun-2013 Elliott Hughes <enh@google.com> Fix @deprecated javadoc orthography.

Change-Id: I6db6d91e21b8e1aca5b5338534196fd5bdef8a06
4f97bfe0d9e6f4bdb43fff91f341f4722af16301 09-Apr-2013 Elliott Hughes <enh@google.com> Revert "Revert "Clean up some code that's dead now we're using OkHttp.""

This reverts commit 7653089cb7609f6269aecd68e839c40941cb1a46

Change-Id: Ie3c0fd1f5d51d61e55ec3a581464943e63716b38
7653089cb7609f6269aecd68e839c40941cb1a46 09-Apr-2013 Elliott Hughes <enh@google.com> Revert "Clean up some code that's dead now we're using OkHttp."

This reverts commit a77a6f93de75a1d9c51ea142013c5fd54c85a359

Change-Id: If6cfe5031efd2d36eae4af5774757667efcb67a2
a77a6f93de75a1d9c51ea142013c5fd54c85a359 08-Apr-2013 Elliott Hughes <enh@google.com> Clean up some code that's dead now we're using OkHttp.

Change-Id: I4b85c2419e73dc15f921157ce3221225a06b30bf
c9c9e38d3f85a9ad0fda7c59b342eb461ab23eb8 08-Apr-2013 Elliott Hughes <enh@google.com> Always throw IOException in IoUtils.deleteContent.

This way, if there's some I/O problem that means we can't set up an
HTTP cache, the app can stumble on cacheless rather than fail to start.

Bug: 8270511
Change-Id: I48331151e4f649a6c8120daf03424708cb409fbe
6d17baa25d349e2659eb16fe5eef3088d48e5e22 05-Nov-2012 Elliott Hughes <enh@google.com> Make System.loadLibrary use open(2) rather than stat(2).

This will let us remove read permission from directories containing .so files.

Bug: 6485312
Change-Id: I72daa265ce54747fc91cdb9d915a05a2464041bb
9726be51ed6f9695357bc8f11a547d9beaa79fce 16-Oct-2012 Brian Carlstrom <bdc@google.com> Fix Thread.interrupt and PipedInputStream/PipedReader issues found by InterruptedStreamTest

Bug: 6951157
Change-Id: I558f8eb5c435f01c98c080ac38cc7c165e7aee25
9b510df35b57946d843ffc34cf23fdcfc84c5220 28-May-2011 Elliott Hughes <enh@google.com> Make ErrnoException a checked exception.

Bug: 4486011
Change-Id: I1877ce593d441653f75ab14884aa2d85f52652ad
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
553d98af897f7202de5e5a776287de0b5ca8fe39 19-May-2011 Elliott Hughes <enh@google.com> Expose accept(2).

The implementation of PlainSocketImpl.accept is made ugly by the fact that the
SocketImpl we mutate may share its FileDescriptor with a SocketChannel, so we
need to mutate the FileDescriptor itself, and can't simply swap in a new one.
I've raised http://b/4452981 to see if we can integrate the nio and io socket
classes more closely, to avoid this kind of mess.

Bug: 3107501
Change-Id: I4964b64c25e936a44d1e4c22504ca29bba247ab6
23ec09188303a874b3b391f96ae0a29af002bff9 19-May-2011 Elliott Hughes <enh@google.com> Implement recvfrom(2).

This one's a little bit hairy because of multiple return values.

Bug: 3107501
Change-Id: I3bd35647d94bb6bc2192d6f31a39ecca07a3926e
90d96a4f168b7e56cff54dc94dca2f3cde60ebcd 17-May-2011 Elliott Hughes <enh@google.com> Add sendto(2) and reimplement all network writes in terms of it.

Note that this doesn't fix http://b/4182806.

Bug: 3107501
Change-Id: I9b56eae226389a63a12b4c0499d40d5a54a462e2
e27d02044ec399884bfd4343d513bf270b9b9b11 16-May-2011 Elliott Hughes <enh@google.com> Remove OSNetworkSystem.close.

For now I'm keeping AsynchronousCloseMonitor as a special case in native code.
We can see about doing something more general-purpose in a later pass.

Bug: 3107501
Change-Id: Ib79b9fc0bebfafc2d14896d957bd8591ae8e6e97
2bad9bff258de6275bd3847e5e9f3169b0a93c61 12-May-2011 Elliott Hughes <enh@google.com> Reimplement OSNetworkSystem.isConnected in Java.

We can do this in Java now we've exposed poll(2).

Change-Id: I9f2700d09134198c1cd2681e3814fb482e8e271c
f589846f86761ffea3c06ab9d105d3f19328d121 11-May-2011 Jesse Wilson <jessewilson@google.com> Address code review comments to Adopt DiskLruCache change.

That change was submitted too early. This is the missing
follow-up.

Change-Id: I521455a7d249f8841c989561775c91d4368a8966
http://b/3180373
433e3fac172d0c4449051b0c61c0c63b298a0903 11-May-2011 Jesse Wilson <jessewilson@google.com> Adopt DiskLruCache in HttpResponseCache.

http://b/3180373

Change-Id: I55ed45c5d0b8fc72cf50e8912416367ac802dc7a
b4edeb4bd130b1a1d0ba33f374d411cf48590f8e 10-May-2011 Jesse Wilson <jessewilson@google.com> DiskLruCache, backing store for the HttpResponseCache.

This is a work in progress. This cache doesn't yet have support
for eviction or journal compaction. This isn't intended to ever
be public API but it should still have some user documentation.

Change-Id: I62800661a8170ee117622b799836f17226abb7e4
http://b/3180373

Conflicts:

luni/src/main/java/libcore/io/IoUtils.java
996bf79565ac88402920bd826d6f85952c83be20 10-May-2011 Elliott Hughes <enh@google.com> Expose connect(2).

The new NET_FAILURE_RETRY in Posix.cpp is intended to replace the legacy one
in NetFd.h, but during the transition we need both. The new one also takes care
of the asynchronous Socket.close semantics, and changes the behavior when the
FileDescriptor is invalid on entry: that is now reported as EBADF; it's only
reported as "Socket closed" when we've been round the loop at least once,
giving us reason to believe the socket was ever open. Having had to debug this
distinction, I think the new semantics are less confusing.

Bug: 3107501
Change-Id: I243dc4fa2eddde7ba40e9b66ec8fc555bc4e80f9
da15009528cc8300a6251f1d0931ac8657c9fc31 09-May-2011 Elliott Hughes <enh@google.com> Expose bind(2).

I've renamed the java.net.InetAddress to struct sockaddr conversion functions
too, after initially screwing up this patch by copy & pasting a usage of the
one that only one caller actually wants. Now the name's so ugly no-one will
be likely to use it by accident.

Bug: 3107501
Change-Id: I869a8d27fc40e462505e02bf25a67e771a403e92
d6ecf9222ec65a08e99f15fcc4ec024f0fffd13a 04-May-2011 Elliott Hughes <enh@google.com> Fix non-blocking connects.

The key change here is reintroducing the boolean return value, which we need
as long as the native code treats EINPROGRESS as a special case which doesn't
throw.

The rest is just drive-by incremental cleanup of the code.

Change-Id: I761b052adbb14e912c3853a35327f8a589cd4023
220c0af1763283b75617226efe3919c3e3b044c8 30-Apr-2011 Elliott Hughes <enh@google.com> Rewrite blocking connects in terms of the non-blocking primitives.

This simplifies OSNetworkSystem, getting us closer to replacing the
connect(2)-related bits with our new POSIX interface. It also lets
us remove cruft on the Java side that was resetting the socket's
blocking/non-blocking state (which should never have been touched),
which in turn fixes bug 4193212.

Detail messages for socket timeouts get better too, now we're throwing
on the Java side.

The only thing that's worse is that we used to get away with throwing
a checked exception from native code, which simplified our "throws"
clauses. Now we actually have to jump through a few hoops to make javac
happy. (Especially awkward because SocketTimeoutException isn't a
SocketException.) Stupid checked exceptions.

Bug: 4193212
Bug: 3107501
Change-Id: I00695d22094e6d785458dfbb7050fbaecf2db89f
a37e971343883bb582a93ffbd9f0ba84f10e55ba 21-Apr-2011 Elliott Hughes <enh@google.com> Rewrite NetworkInterface.

This is part of the POSIX work, but also fixes a bug that asked for down
interfaces to be returned. Additionally, I found a few bugs while rewriting
this code. Most notably, we used to return a bogus broadcast address for
the loopback interface. The only difference I notice between us and the RI
when running on the host is that the RI claims that 127.0.0.1 has a prefix
length of 0 rather than 8. I believe that we are correct on this issue.

Bug: 4082343, 3107501
Change-Id: I677e0698e3a86676b4332b5d56fe514a99c3ddc0
ae394a866dd86df8819b652dfe00b3d2c7ee204c 20-Apr-2011 Elliott Hughes <enh@google.com> Remove "java.net.preferIPv6Addresses", which has been true since Eclair.

Also ensure all javadoc references to RFCs are links.

Change-Id: I58b08a8ead08d6eab018e19ec2cff7d60f2b06e6
4f11ebea266eada830d507b8f011e811a8e5d7bc 20-Apr-2011 Elliott Hughes <enh@google.com> Add getnameinfo(3) (and gai_strerror(3)).

There's quite a large corresponding change to InetAddress, plus I've changed
the documentation for all the Permission classes to match the handful that
we'd already documented as legacy cruft.

Bug: http://b/3107501
Change-Id: Ia67aba79f0ab13e64085bd4a2df20ad0776bcc5b
b974666d79ebc392b37ec1ae83aae57ae6331c08 06-Apr-2011 Elliott Hughes <enh@google.com> Finish setsockopt(2).

Bug: 3107501
Change-Id: I8f026dcba78acb555834bdcc594e114238f3cc52
438cb9e440d250c8aa5daf4fae0c400dce8b1499 02-Apr-2011 Elliott Hughes <enh@google.com> Add MCAST_JOIN_GROUP/MCAST_LEAVE_GROUP setsockopt(2).

Bug: 3107501
Change-Id: I576f45f8c67b6172888bc0541e3d3a462bfa311a
c63f0d4e80a9fd3bdf99cd438d108b750226736a 02-Apr-2011 Elliott Hughes <enh@google.com> Add more of setsockopt(2).

This covers all the easy cases. I'll do the awkward ones separately.

Bug: 3107501
Change-Id: Ie424290e0bef76516d0c57e9c077cb1c202381ad
c84000159bb1770972c308da924e9c90db4024a0 01-Apr-2011 Elliott Hughes <enh@google.com> Remove hacks for non-dual-stack situations.

There's also a behavioral change here in code that previously said TODO.
Our current intention is that we always set both IPv4 and IPv6 options (when
coming via the java.net interfaces, which don't allow you to differentiate),
always return the IPv6 options (since it can't matter). If you need greater
control (which was never possible before), you'll be able to use the new
APIs soon.

The SocketOptions.IP_MULTICAST_IF (IPv4) and SocketOptions.IP_MULTICAST_IF2
(IPv6) distinction remains, because that's exposed java.net API.

CompatibleSocketAddress gets a lot simpler, but it looks like the kernel
still doesn't like an IN_ANY bind(2) on a dual-stack AF_INET6 socket. This
is unfortunate because it means callers have a decision to make, preventing
us from moving that code into inetAddressToSocketAddress.

Bug: 3107501
Change-Id: Ifa694d936a81af143a40f404b12470045e644fa8
0a9d1ee45a9884a9616624d747172e18734e8fe0 31-Mar-2011 Elliott Hughes <enh@google.com> Add getsockname(2) and getsockopt(2).

Bug: 3107501
Change-Id: Ibb0d5a576ecb46e51dbda6051776145eec9e7fe1
e8fad0e2a8787fd46654d1cc9e477b353a958451 30-Mar-2011 Elliott Hughes <enh@google.com> Fix build.

Change-Id: I29628c87ac3bd1feb0169af84f0cbc3ddf4e430d
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
454a95f6a28855aa3c88d168b15a45bf315efc99 30-Mar-2011 Elliott Hughes <enh@google.com> Add socket(2) and start adding setsockopt(2).

I've added just enough setsockopt to keep the hack from our old socket
creation code. More later (but not necessarily right away).

Bug: 3107501
Change-Id: Id57bdd3c760bc58ed79d675b268c55493cbc24c8
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
461d0d860814c68154d8dd06d24f94118f33d28a 29-Mar-2011 Elliott Hughes <enh@google.com> Add ioctl(2) for int*.

I'm not adding the "struct ifreq" stuff yet because that's really hairy and I
plan on rewriting the NetworkInterface implementation anyway, so it'll mainly
be based on /proc. With any luck, we won't even need those other ioctls then.

I'm not sure _this_ ioctl is a good idea, but it does seem like a slight
improvement on the old code, and we can always move it back out if/when these
APIs become more public.

Bug: 3107501
Change-Id: Iceac15e4a107c33bfc8795976a747c2ffa59a183
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
26c7025a7a919044771fb89031161bd26fe03032 26-Mar-2011 Elliott Hughes <enh@google.com> Add read(2).

For both byte[]s and ByteBuffers.

Bug: 3107501
Change-Id: I93b781069ade4507371c8fe8c5fda0163fbb2dbb
fc549a0b0388987b26dea524894d75a63d14783b 25-Mar-2011 Elliott Hughes <enh@google.com> Add fcntl(2).

I initially used overloading, but that actually decreases safety in practice
because which overload you need is (uniquely) determined by the specific
command you're issuing. Forcing callers to explicitly state what they're
doing works around this. As it was, I had to use strace(1) to find my bug.

Bug: 3107501
Change-Id: Ia54b72dd6453372922f01b22f382eb93ac91aaa7
41f0605d2c809bd9bc1c0fb68d86b49a0f59b6c5 24-Mar-2011 Elliott Hughes <enh@google.com> Add pipe(2).

This lets us kill quite a bit of IoUtils.

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

Bug: 3107501
Change-Id: I404030b4c678862465d04f723a6a324663e0af25
a7a70410e26802f3ab480b08a1ab499338cb6f7e 03-Oct-2010 Jesse Wilson <jessewilson@google.com> Use IoUtils.closeQuietly where possible.

Change-Id: I354c1e00b7068108032d09c0a1c38e29f6283fb0
bffb058e565a97f838247f1e092b0d17b26cb68e 21-Sep-2010 Elliott Hughes <enh@google.com> Stop doing unbuffered file I/O in ZoneInfoDB.

Use the new memory-mapped code for the index as well as for individual time
zones. This takes the (once-only, during boot) index-reading time down
from ~90ms to ~20ms. DataInputStream(BufferedInputStream(FileInputStream))
would have got us down to ~40ms.

Also remove duplication amongst code snippets that want to read a whole file
into a byte[].

Bug: 3014973
Change-Id: I9d8a326438663314b7f5ee0145cda32ea335f41d
f14cadb15b06371fb9a6daf885dc1c4bccf975b9 10-Aug-2010 Elliott Hughes <enh@google.com> Minor TimeZone cleanup.

Getting ready to do some real work here, I thought I'd improve the
documentation and remove some cruft.

Bug: 2870945
Change-Id: I771badc8afa5c0a5f77880f64e1542d77672d984
440ba565fa5384bc23255fbc412f7b97fcbdccd9 04-Aug-2010 Elliott Hughes <enh@google.com> Rename setNonBlocking to setBlocking.

This makes the boolean argument less confusing.

Change-Id: Ic226f6d3c5afe8e15a95e74917656424f8a448fe
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