Skip to content

Commit

Permalink
Merge pull request mozilla#563 from marco-c/pimproxy_natives
Browse files Browse the repository at this point in the history
Basic support for the PIM API
  • Loading branch information
mykmelez committed Nov 11, 2014
2 parents d1a1f77 + db91c36 commit 319da28
Show file tree
Hide file tree
Showing 8 changed files with 617 additions and 19 deletions.
42 changes: 25 additions & 17 deletions java/custom/com/sun/cldc/i18n/j2me/UTF_8_Reader.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,15 @@

/** Reader for UTF-8 encoded input streams. */
public class UTF_8_Reader extends StreamReader {
boolean initialized = false;

/** Constructs a UTF-8 reader. */
public UTF_8_Reader() {
}

public Reader open(InputStream in, String enc)
throws UnsupportedEncodingException {
super.open(in, enc);

// Read the whole stream in memory
byte[] buffer = new byte[1024];
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
int numRead = 0;
while ((numRead = in.read(buffer)) > -1) {
output.write(buffer, 0, numRead);
}
output.flush();
} catch (Exception e) {
throw new UnsupportedEncodingException("Failed to read from the stream");
}

init(output.toByteArray());

return this;
}

Expand All @@ -70,7 +56,29 @@ public Reader open(InputStream in, String enc)
* @exception IOException is thrown if the input stream
* could not be read for the raw unconverted character
*/
public native int read(char cbuf[], int off, int len) throws IOException;
public native int readNative(char cbuf[], int off, int len);
public int read(char cbuf[], int off, int len) throws IOException {
if (!initialized) {
// Read the whole stream in memory
byte[] buffer = new byte[1024];
ByteArrayOutputStream output = new ByteArrayOutputStream();
try {
int numRead = 0;
while ((numRead = in.read(buffer)) > -1) {
output.write(buffer, 0, numRead);
}
output.flush();
} catch (Exception e) {
throw new UnsupportedEncodingException("Failed to read from the stream");
}

init(output.toByteArray());

initialized = true;
}

return readNative(cbuf, off, len);
}

/**
* Mark the present position in the stream.
Expand Down
Loading

0 comments on commit 319da28

Please sign in to comment.