Java 8 has reached end of support
and will be
deprecated
on January 31, 2026. After deprecation, you won't be able to deploy Java 8
applications, even if your organization previously used an organization policy to
re-enable deployments of legacy runtimes. Your existing Java
8 applications will continue to run and receive traffic after their
deprecation date. We recommend that
you
migrate to the latest supported version of Java.
FileWriteChannel (Google App Engine API for Java)
Stay organized with collections
Save and categorize content based on your preferences.
-
- All Superinterfaces:
- java.lang.AutoCloseable, java.nio.channels.Channel, java.io.Closeable, java.nio.channels.WritableByteChannel
Deprecated.
@Deprecated
public interface FileWriteChannel
extends java.nio.channels.WritableByteChannel
A
WritableByteChannel
for appending bytes to an
AppEngineFile
. In addition to the behavior specified by
WritableByteChannel
this class also exposes a
sequence key
feature which may be used to
recover from certain types of failures.
An instance of FileWriteChannel
is obtained from the method
FileService.openWriteChannel(AppEngineFile, boolean)
.
A FileWriteChannel
is associated with a single App Engine request and
may not be used outside of the request in which it is constructed. Therefore
an instance of FileWriteChannel
should not be cached between
requests. Instead, close
the channel at the end of the
request (without finalizing
), cache the AppEngineFile
or just the path
, and
create a new FileWriteChannel
in a later request.
When the channel is
opened
, the
underlying file may be locked. Successful aquisition of the
lock means that no other App Engine request will be able to read or write the
underlying file until the lock is released.
One of the close()
methods should be invoked before the request
terminates. The version closeFinally()
causes the underlying file to
be finalized. Once a file is finalized it may be read, and it may not
be written. In order to finalize a file it is necessary to hold the lock for
the file. If no close()
method is invoked before the request
terminates then Channel.close()
will implicitly be invoked and so the file
will not be finalized. All of the close()
methods have the
side-effect of releasing a lock if one is held.
Just like WritableByteChannel
If one thread initiates a write operation upon a channel
then any other thread that attempts to initiate another write operation will block until the
first operation is complete.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Deprecated Methods
Modifier and Type |
Method and Description |
void |
closeFinally()
Deprecated.
Close the channel and finalize the file.
|
int |
write(java.nio.ByteBuffer src,
java.lang.String sequenceKey)
Deprecated.
As specified by WritableByteChannel.write(ByteBuffer) with the
addition of the sequenceKey parameter.
|
-
Methods inherited from interface java.nio.channels.WritableByteChannel
write
-
Methods inherited from interface java.nio.channels.Channel
close, isOpen
-
-
Method Detail
-
write
int write(java.nio.ByteBuffer src,
java.lang.String sequenceKey)
throws java.io.IOException
Deprecated.
As specified by
WritableByteChannel.write(ByteBuffer)
with the
addition of the
sequenceKey
parameter. If this parameter is not
null
then it will be passed to the back end repository and recorded
as the last good sequence key if the back end write succeeds. In this case,
if the
sequenceKey
is not strictly lexicographically greater than
the last good sequence key the back end has already recorded (if there is
one), a
KeyOrderingException
will be thrown from which the last
good sequence key may be retrieved via the method
KeyOrderingException.getLastGoodSequenceKey()
. By making use of
this feedback system it is possible to recover from certain types of
failures that it would otherwise be difficult to recover from. For example,
if bytes are being written to a file in a series of App Engine Task Queue
tasks and one of the tasks is retried, this technique can be used to avoid
writing the same bytes twice. As another example, if during a series of
writes the back end loses some of the bytes of a file due to a back end
system failure, this feedback system may be used to inform the client of
the last write after which the data corruption begins, thus enabling the
client to resend all bytes after that point.
- Throws:
java.io.IOException
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-06-16 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-06-16 UTC."],[[["\u003cp\u003e\u003ccode\u003eFileWriteChannel\u003c/code\u003e is a deprecated \u003ccode\u003eWritableByteChannel\u003c/code\u003e used for appending bytes to an \u003ccode\u003eAppEngineFile\u003c/code\u003e, offering a sequence key feature for failure recovery.\u003c/p\u003e\n"],["\u003cp\u003eInstances of \u003ccode\u003eFileWriteChannel\u003c/code\u003e should not be cached between requests and must be closed within the same request they were constructed, ensuring locks are released.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ecloseFinally()\u003c/code\u003e method finalizes the associated file, making it readable but no longer writable, requiring that the file lock is currently being held.\u003c/p\u003e\n"],["\u003cp\u003eThe \u003ccode\u003ewrite\u003c/code\u003e method, in addition to writing to the channel, accepts a sequence key for tracking successful writes, facilitating recovery from certain failures by identifying the last good sequence key.\u003c/p\u003e\n"],["\u003cp\u003eFile locking ensures that only one request at a time can access the file, whether for reading or writing, preventing conflicts.\u003c/p\u003e\n"]]],[],null,["# FileWriteChannel (Google App Engine API for Java)\n\ncom.google.appengine.api.files\n\nInterface FileWriteChannel\n--------------------------\n\n-\n\n All Superinterfaces:\n : java.lang.AutoCloseable, java.nio.channels.Channel, java.io.Closeable, java.nio.channels.WritableByteChannel\n\n *** ** * ** ***\n\n Deprecated.\n\n ```\n @Deprecated\n public interface FileWriteChannel\n extends java.nio.channels.WritableByteChannel\n ``` \n A `WritableByteChannel` for appending bytes to an [`AppEngineFile`](../../../../../com/google/appengine/api/files/AppEngineFile.html \"class in com.google.appengine.api.files\"). In addition to the behavior specified by `WritableByteChannel` this class also exposes a [`sequence key`](../../../../../com/google/appengine/api/files/FileWriteChannel.html#write-java.nio.ByteBuffer-java.lang.String-) feature which may be used to recover from certain types of failures.\n\n\n An instance of `FileWriteChannel` is obtained from the method\n [`FileService.openWriteChannel(AppEngineFile, boolean)`](../../../../../com/google/appengine/api/files/FileService.html#openWriteChannel-com.google.appengine.api.files.AppEngineFile-boolean-).\n\n\n A `FileWriteChannel` is associated with a single App Engine request and\n may not be used outside of the request in which it is constructed. Therefore\n an instance of `FileWriteChannel` should not be cached between\n requests. Instead, `close ` the channel at the end of the\n request (without [`finalizing`](../../../../../com/google/appengine/api/files/FileWriteChannel.html#closeFinally--)), cache the `AppEngineFile` or just the [`path`](../../../../../com/google/appengine/api/files/AppEngineFile.html#getFullPath--), and\n create a new `FileWriteChannel` in a later request.\n\n\n When the channel is\n [`opened`](../../../../../com/google/appengine/api/files/FileService.html#openWriteChannel-com.google.appengine.api.files.AppEngineFile-boolean-), the\n underlying file may be **locked**. Successful aquisition of the\n lock means that no other App Engine request will be able to read or write the\n underlying file until the lock is released.\n\n\n One of the `close()` methods should be invoked before the request\n terminates. The version [`closeFinally()`](../../../../../com/google/appengine/api/files/FileWriteChannel.html#closeFinally--) causes the underlying file to\n be *finalized* . Once a file is finalized it may be read, and it may not\n be written. In order to finalize a file it is necessary to hold the lock for\n the file. If no `close()` method is invoked before the request\n terminates then `Channel.close()` will implicitly be invoked and so the file\n will not be finalized. All of the `close()` methods have the\n side-effect of releasing a lock if one is held.\n\n Just like `WritableByteChannel` If one thread initiates a write operation upon a channel\n then any other thread that attempts to initiate another write operation will block until the\n first operation is complete.\n\n \u003cbr /\u003e\n\n \u003cbr /\u003e\n\n \u003cbr /\u003e\n\n-\n -\n\n ### Method Summary\n\n -\n\n ### Methods inherited from interface java.nio.channels.WritableByteChannel\n\n `write`\n\n \u003c!-- --\u003e\n\n -\n\n ### Methods inherited from interface java.nio.channels.Channel\n\n`close, isOpen` \n-\n -\n\n ### Method Detail\n\n\n -\n\n #### write\n\n ```\n int write(java.nio.ByteBuffer src,\n java.lang.String sequenceKey)\n throws java.io.IOException\n ``` \n Deprecated. \n As specified by `WritableByteChannel.write(ByteBuffer)` with the addition of the `sequenceKey` parameter. If this parameter is not `null` then it will be passed to the back end repository and recorded as the last good sequence key if the back end write succeeds. In this case, if the `sequenceKey` is not strictly lexicographically greater than the last good sequence key the back end has already recorded (if there is one), a [`KeyOrderingException`](../../../../../com/google/appengine/api/files/KeyOrderingException.html \"class in com.google.appengine.api.files\") will be thrown from which the last good sequence key may be retrieved via the method [`KeyOrderingException.getLastGoodSequenceKey()`](../../../../../com/google/appengine/api/files/KeyOrderingException.html#getLastGoodSequenceKey--). By making use of this feedback system it is possible to recover from certain types of failures that it would otherwise be difficult to recover from. For example, if bytes are being written to a file in a series of App Engine Task Queue tasks and one of the tasks is retried, this technique can be used to avoid writing the same bytes twice. As another example, if during a series of writes the back end loses some of the bytes of a file due to a back end system failure, this feedback system may be used to inform the client of the last write after which the data corruption begins, thus enabling the client to resend all bytes after that point.\n\n Throws:\n : `java.io.IOException`\n\n\n -\n\n #### closeFinally\n\n ```\n void closeFinally()\n throws java.lang.IllegalStateException,\n java.io.IOException\n ``` \n Deprecated. \n Close the channel and finalize the file. After the file is finalized it may be read, and it may no longer be written.\n\n Throws:\n : `java.lang.IllegalStateException` - if the current request does not hold the lock\n for the file\n : `java.io.IOException` - if any unexpected problem occurs"]]