repository.grepcode.com$java$root@jdk$openjdk@6-b14@java$io$ByteArrayInputStream.java
oh
o
[{"sl":104,"sc":-1,"el":104,"ec":-1,"m":"new java.io.ByteArrayInputStream(byte[]) may expose internal representation by storing an externally mutable object into ByteArrayInputStream.buf","p":2,"t":"EI_EXPOSE_REP2","a":"EI2","c":"MALICIOUS_CODE"},{"sl":124,"sc":-1,"el":124,"ec":-1,"m":"new java.io.ByteArrayInputStream(byte[], int, int) may expose internal representation by storing an externally mutable object into ByteArrayInputStream.buf","p":2,"t":"EI_EXPOSE_REP2","a":"EI2","c":"MALICIOUS_CODE"},{"sl":260,"sc":-1,"el":260,"ec":-1,"m":"Inconsistent synchronization of java.io.ByteArrayInputStream.pos; locked 11% of time","p":5,"t":"IS2_INCONSISTENT_SYNC","a":"IS","c":"MT_CORRECTNESS"},{"sl":54,"sc":-1,"el":54,"ec":-1,"m":"Inconsistent synchronization of java.io.ByteArrayInputStream.buf; locked 1% of time","p":5,"t":"IS2_INCONSISTENT_SYNC","a":"IS","c":"MT_CORRECTNESS"},{"sl":58,"sc":-1,"el":58,"ec":-1,"m":"Inconsistent synchronization of java.io.ByteArrayInputStream.count; locked 11% of time","p":5,"t":"IS2_INCONSISTENT_SYNC","a":"IS","c":"MT_CORRECTNESS"},{"sl":260,"sc":-1,"el":260,"ec":-1,"m":"Inconsistent synchronization of java.io.ByteArrayInputStream.mark; locked 50% of time","p":2,"t":"IS2_INCONSISTENT_SYNC","a":"IS","c":"MT_CORRECTNESS"}]
I have a String that I want to use as an InputStream. In Java 1.0, you could use java.io.StringBufferInputStream, but that has been @Deprecrated (with good reason--you cannot specify the character set encoding):
This class does not properly convert
characters into bytes. As of JDK 1.1,
the preferred way to create a stream
from a string is via the StringReader
class.
You can create...
How can I create an InputStream object from a XML Document or Node object to be used in xstream? I need to replace the ??? with some meaningful code. Thanks.
Document doc = getDocument();
InputStream is = ???;
MyObject obj = (MyObject) xstream.fromXML(is);
I'm not used to working with streams in Java - how do I create an InputStream from a String?
Can we convert a byte array into an InputStream in Java? I have been looking on the internet but couldn't find it.
I have a method that has an InputStream as argument.
The InputStream cph I have is base64 encoded so I had to decode it using
BASE64Decoder decoder = new BASE64Decoder();
byte[] decodedBytes = decoder.decodeBuffer(cph);
Now how do I convert decodedBytes again to InputStream?
I need to replace code using RandomAccessFile with one that uses in-memory byte buffer (such as byte[] or derivatives like ByteArrayInputStream). Is there some API (byte array wrapper?) that has interface similar to RandomAccessFile, with seek() and streamish read() which I could plug in one-to-one?
We have this use case where we would like to compress and store objects (in-memory) and decompress them as and when required.
The data we want to compress is quite varied, from float vectors to strings to dates.
Can someone suggest any good compression technique to do this ?
We are looking at ease of compression and speed of decompression as the most important factors.
Thanks.
Not sure about how I am supposed to do this. Any help would be appreciated
I have a contact that is experiencing trouble with SAX when parsing RSS and Atom files. According to him, it's as if text coming from the Item elements is truncated at an apostrophe or sometimes an accented character. There seems to be a problem with encoding too.
I've given SAX a try and I have some truncating taking place too but haven't been able to dig further. I'd appreciate some suggesti...
I am trying to understand this snippet of code
DataInputStream stream =
new DataInputStream(
new ByteArrayInputStream(messageBuffer));
int messageLength = stream.readInt();
char recordType = (char) stream.readByte();
byte padding = stream.readByte();
short numberRecords = stream.readShort();
message...
I am having some trouble properly retrieving blob data from my database using java in my JSF 2.0 application. The first problem I am having is on my getter method for the Blob named "file" I get an error saying that "Basic attributes can only be of the following types..." basically saying that I can not return a Blob object. My code looks like what is below. Even with the error my code compiles...
I'm trying to create a RESTful webservice using a Java Servlet. The problem is I have to pass via POST method to a webserver a request. The content of this request is not a parameter but the body itself.
So I basically send from ruby something like this:
url = URI.parse(@host)
req = Net::HTTP::Post.new('/WebService/WebServiceServlet')
req['Content-Type'] = "text/xml"
# req.basic_auth 'accoun...
Please provide pointers to help me mock that java InputStream object.
This is the line of code that I would wish to Mock:
InputStreamReader inputData = new InputStreamReader(System.in);
bufferdReader = new BufferedReader(inputData);
bufferdReader.readLine();
I have the following problem. I have C code that acquires a PNG image as basically raw data and keeps it in memory. I would like this raw data to be translated to a BufferedImage in Java, through the use of JNI. Does anyone know any way of doing this or has done this before?
I have a Base64 string that's been gzipped in .NET and I would like to convert it back into a string in Java. I'm looking for some Java equivalents to the C# syntax, particularly:
Convert.FromBase64String
MemoryStream
GZipStream
Here's the method I'd like to convert:
public static string Decompress(string zipText) {
byte[] gzipBuff = Convert.FromBase64String(zipText);
using (Memor...
As the title, I create a ByteArray to store the file in blob like this:
byte[] red_buf = myCursor.getBlob(1);
And I wanna use FileOutputStream to open.
But I don't know how to do.
Can anyone give me a example or website please ??
I am using the Java Jersey to implement a REST service.
One thing my service should provide is a file download option.
These files are quite big and are constructed from data from db.
Currently I am fetching all data from the db and saving it to a file
and returning a
Response.ok().entity(new FileInputStream(file)).build();
Is there a way how I can start serving the file without fully down...
Is there a possibility to generate an java.security.cert.X509Certificate from an byte[]?
I have a Base64-encoded object with the following header:
application/x-xfdl;content-encoding="asc-gzip"
What is the best way to proceed in decoding the object? Do I need to strip the first line? Also, if I turn it into a byte array (byte[]), how do I un-gzip it?
Thanks!
I think I misspoke initially. By saying the header was
application/x-xfdl;content-encoding="asc-gzip"
I meant this...
I am trying to write a method which receives a serializable object (implements Serializable) o and a method m.
The method should compare the state of o before invoking m and after invoking m, and tell if invoking m changed o. It should check if the bits representing o were changed after the methods. Ho can I do it?
I want to write a BigInteger to a file.
What is the best way to do this.
Of course I want to read (with the program, not by human) it from an inputstream.
Do I have to use an ObjectOutputStream or are there better ways?
The purpose is to use as less bytes as possible.
Thanks
Martijn
I have a code base that makes extensive use of files to represent a single data object. I have refactored the code so that the data object is now an explicit java object that mostly hides interaction with the underlying file system. However, we use a few external tools (like Weka), that read and write files.
Ideally, I would like to have a subclass of File that I can pass to these other li...
A
ByteArrayInputStream contains
an internal buffer that contains bytes that
may be read from the stream. An internal
counter keeps track of the next byte to
be supplied by the
read method.
Closing a ByteArrayInputStream has no effect. The methods in
this class can be called after the stream has been closed without
generating an IOException.
An array of bytes that was provided
by the creator of the stream. Elements
buf[0]
through
buf[count-1] are the
only bytes that can ever be read from the
stream; element
buf[pos] is
the next byte to be read.
The index of the next character to read from the input stream buffer.
This value should always be nonnegative
and not larger than the value of
count.
The next byte to be read from the input stream buffer
will be
buf[pos].
The currently marked position in the stream.
ByteArrayInputStream objects are marked at position zero by
default when constructed. They may be marked at another
position within the buffer by the
mark() method.
The current buffer position is set to this point by the
reset() method.
If no mark has been set, then the value of mark is the offset
passed to the constructor (or 0 if the offset was not supplied).
The index one greater than the last valid character in the input
stream buffer.
This value should always be nonnegative
and not larger than the length of
buf.
It is one greater than the position of
the last byte within
buf that
can ever be read from the input stream buffer.
Creates a
ByteArrayInputStream
so that it uses
buf as its
buffer array.
The buffer array is not copied.
The initial value of
pos
is
0 and the initial value
of
count is the length of
buf.
- Parameters:
buf the input buffer.
Creates
ByteArrayInputStream
that uses
buf as its
buffer array. The initial value of
pos
is
offset and the initial value
of
count is the minimum of
offset+length
and
buf.length.
The buffer array is not copied. The buffer's mark is
set to the specified offset.
- Parameters:
buf the input buffer.offset the offset in the buffer of the first byte to read.length the maximum number of bytes to read from the buffer.
this.count = Math.min(offset + length, buf.length);
Reads the next byte of data from this input stream. The value
byte is returned as an
int in the range
0 to
255. If no byte is available
because the end of the stream has been reached, the value
-1 is returned.
This read method
cannot block.
- Returns:
- the next byte of data, or
-1 if the end of the
stream has been reached.
public synchronized int read() { Reads up to
len bytes of data into an array of bytes
from this input stream.
If
pos equals
count,
then
-1 is returned to indicate
end of file. Otherwise, the number
k
of bytes read is equal to the smaller of
len and
count-pos.
If
k is positive, then bytes
buf[pos] through
buf[pos+k-1]
are copied into
b[off] through
b[off+k-1] in the manner performed
by
System.arraycopy. The
value
k is added into
pos
and
k is returned.
This read method cannot block.
- Parameters:
b the buffer into which the data is read.off the start offset in the destination array blen the maximum number of bytes read.- Returns:
- the total number of bytes read into the buffer, or
-1 if there is no more data because the end of
the stream has been reached. - Throws:
java.lang.NullPointerException If b is null.java.lang.IndexOutOfBoundsException If off is negative,
len is negative, or len is greater than
b.length - off
public synchronized int read(byte b[], int off, int len) { } else if (off < 0 || len < 0 || len > b.length - off) { Skips
n bytes of input from this input stream. Fewer
bytes might be skipped if the end of the input stream is reached.
The actual number
k
of bytes to be skipped is equal to the smaller
of
n and
count-pos.
The value
k is added into
pos
and
k is returned.
- Parameters:
n the number of bytes to be skipped.- Returns:
- the actual number of bytes skipped.
public synchronized long skip(long n) { Returns the number of remaining bytes that can be read (or skipped over)
from this input stream.
The value returned is count - pos,
which is the number of bytes remaining to be read from the input buffer.
- Returns:
- the number of remaining bytes that can be read (or skipped
over) from this input stream without blocking.
Tests if this
InputStream supports mark/reset. The
markSupported method of
ByteArrayInputStream
always returns
true.
Set the current marked position in the stream.
ByteArrayInputStream objects are marked at position zero by
default when constructed. They may be marked at another
position within the buffer by this method.
If no mark has been set, then the value of the mark is the
offset passed to the constructor (or 0 if the offset was not
supplied).
Note: The readAheadLimit for this class
has no meaning.
public void mark(int readAheadLimit) { Resets the buffer to the marked position. The marked position
is 0 unless another position was marked or an offset was specified
in the constructor.
public synchronized void reset() { Closing a
ByteArrayInputStream has no effect. The methods in
this class can be called after the stream has been closed without
generating an
IOException.