Re: Appending data to file in a MemoryFileSystem.

2019-09-19 Thread William Reynolds
But can't you construct a FileChannel from the FileOutputStream? I 
thought the question was how to seek on an output stream, which the 
example generates.


On 9/19/2019 10:06 AM, Neil C Smith wrote:

On Thu, 19 Sep 2019 at 17:03, William Reynolds
 wrote:

 From https://stackoverflow.com/questions/9558979/java-outputstream-skip-offset

...

FileOutputStream out = new FileOutputStream(file);

There is no File! ;-)

Best wishes,

Neil


--
William Reynolds, Ph.D.
Stellar Science, LLC
wnreyno...@stellarscience.com
www.stellarscience.com
877-763-8268 x710 (v)




smime.p7s
Description: S/MIME Cryptographic Signature


Re: Appending data to file in a MemoryFileSystem.

2019-09-19 Thread Neil C Smith
On Thu, 19 Sep 2019 at 17:03, William Reynolds
 wrote:
>
> From https://stackoverflow.com/questions/9558979/java-outputstream-skip-offset
...
>FileOutputStream out = new FileOutputStream(file);

There is no File! ;-)

Best wishes,

Neil

-
To unsubscribe, e-mail: users-unsubscr...@netbeans.apache.org
For additional commands, e-mail: users-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists



Re: Appending data to file in a MemoryFileSystem.

2019-09-19 Thread William Reynolds
From 
https://stackoverflow.com/questions/9558979/java-outputstream-skip-offset


|try{FileOutputStreamout =newFileOutputStream(file);try{FileChannelch 
=out.getChannel();ch.position(offset);ch.write(ByteBuffer.wrap(data));}finally{out.close();}}catch(IOExceptionex){// 
handle error}|




On 9/19/2019 8:02 AM, Richard Linsdale wrote:

Hopefully somebody can help direct me to a solution to this problem

In a Netbeans plug-in which I am developing, I have created a 
MemoryFileSystem for storage of transient files.


I now wish to add a feature to append data to an existing file (in the 
MemoryFileSystem), but I can't find a solution.


If the file was in the OS file system, then I could use the 
FileUtils.toFile() method to get a  and then use new 
FileWriter (, true) to create a writer with which I could append 
the data.


As the file is in a MemoryFileSystem, use of FileUtils.toFile returns 
null, so it's not a route to follow.


Use of .getOutputStream() returns a valid outputstream, 
but is positioned at the start of the file and will therefore 
overwrite the existing data.


Any suggestions welcome, as I want to avoid copying the existing file 
content to a new file on every append request and then renaming the 
file (which is my probably short term fall back).


In the longer-term, it would be nice to have 
.getOutputStream(boolean append) as a extension to the 
API, but that can come later.


regards

Richard


-
To unsubscribe, e-mail: users-unsubscr...@netbeans.apache.org
For additional commands, e-mail: users-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists



--
William Reynolds, Ph.D.
Stellar Science, LLC
wnreyno...@stellarscience.com
www.stellarscience.com
877-763-8268 x710 (v)



smime.p7s
Description: S/MIME Cryptographic Signature


Re: Appending data to file in a MemoryFileSystem.

2019-09-19 Thread Neil C Smith
On Thu, 19 Sep 2019 at 15:04, Richard Linsdale
 wrote:
> Any suggestions welcome, as I want to avoid copying the existing file
> content to a new file on every append request and then renaming the file
> (which is my probably short term fall back).

The MemoryFileSystem is quite simple, and everything is backed by a
byte[].  What about reading the existing contents with asBytes() and
then writing that into the output stream?  Not much different mind
you!

> In the longer-term, it would be nice to have
> .getOutputStream(boolean append) as a extension to the API,
> but that can come later.

Does it have to be a NetBeans filesystem?  I've seen some NIO2 memory
file systems which have this feature (although are probably doing just
the same thing under the hood).

Best wishes,

Neil

-
To unsubscribe, e-mail: users-unsubscr...@netbeans.apache.org
For additional commands, e-mail: users-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists



Appending data to file in a MemoryFileSystem.

2019-09-19 Thread Richard Linsdale

Hopefully somebody can help direct me to a solution to this problem

In a Netbeans plug-in which I am developing, I have created a 
MemoryFileSystem for storage of transient files.


I now wish to add a feature to append data to an existing file (in the 
MemoryFileSystem), but I can't find a solution.


If the file was in the OS file system, then I could use the 
FileUtils.toFile() method to get a  and then use new 
FileWriter (, true) to create a writer with which I could append 
the data.


As the file is in a MemoryFileSystem, use of FileUtils.toFile returns 
null, so it's not a route to follow.


Use of .getOutputStream() returns a valid outputstream, but 
is positioned at the start of the file and will therefore overwrite the 
existing data.


Any suggestions welcome, as I want to avoid copying the existing file 
content to a new file on every append request and then renaming the file 
(which is my probably short term fall back).


In the longer-term, it would be nice to have 
.getOutputStream(boolean append) as a extension to the API, 
but that can come later.


regards

Richard


-
To unsubscribe, e-mail: users-unsubscr...@netbeans.apache.org
For additional commands, e-mail: users-h...@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists