diff options
author | Matti Tahvonen <matti.tahvonen@itmill.com> | 2011-01-31 14:43:57 +0000 |
---|---|---|
committer | Matti Tahvonen <matti.tahvonen@itmill.com> | 2011-01-31 14:43:57 +0000 |
commit | d6fc0ed8216ad6dc8caf1362c4c5f772e8c8f68c (patch) | |
tree | c8bc19bad4549cb1bde0c544554294467a4f8beb /src/com/vaadin/terminal | |
parent | 16cc003af3ed88d7cb31fe382349a9a7e1b67dc0 (diff) | |
download | vaadin-framework-d6fc0ed8216ad6dc8caf1362c4c5f772e8c8f68c.tar.gz vaadin-framework-d6fc0ed8216ad6dc8caf1362c4c5f772e8c8f68c.zip |
fixes #6361
svn changeset:17091/svn branch:6.5
Diffstat (limited to 'src/com/vaadin/terminal')
-rw-r--r-- | src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java | 75 |
1 files changed, 49 insertions, 26 deletions
diff --git a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java index 5dd99f9f0d..39b5c204a1 100644 --- a/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java +++ b/src/com/vaadin/terminal/gwt/server/AbstractCommunicationManager.java @@ -2164,7 +2164,7 @@ public abstract class AbstractCommunicationManager implements * Counter of how many characters have been matched to boundary string * from the stream */ - int matchedCount = 0; + int matchedCount = -1; /** * Used as pointer when returning bytes after partly matched boundary @@ -2195,6 +2195,12 @@ public abstract class AbstractCommunicationManager implements } else if (bufferedByte >= 0) { /* Purge partially matched boundary if there was such */ return getBuffered(); + } else if (matchedCount != -1) { + /* + * Special case where last "failed" matching ended with first + * character from boundary string + */ + return matchForBoundary(); } else { int fromActualStream = realInputStream.read(); if (fromActualStream == -1) { @@ -2202,38 +2208,54 @@ public abstract class AbstractCommunicationManager implements throw new IOException( "The multipart stream ended unexpectedly"); } - if (boundary[matchedCount] == fromActualStream) { + if (boundary[0] == fromActualStream) { /* - * Going to "buffered mode". Read until full boundary match - * or a different character. + * If matches the first character in boundary string, start + * checking if the boundary is fetched. */ - while (true) { - matchedCount++; - if (matchedCount == boundary.length) { - /* - * The whole boundary matched so we have reached the - * end of file - */ - atTheEnd = true; - return -1; - } - fromActualStream = realInputStream.read(); - if (fromActualStream != boundary[matchedCount]) { - /* - * Did not find full boundary, cache the mismatching - * byte and start returning the partially matched - * boundary. - */ - bufferedByte = fromActualStream; - return getBuffered(); - } - } + return matchForBoundary(); } return fromActualStream; } } /** + * Reads the input to expect a boundary string. Expects that the first + * character has already been matched. + * + * @return -1 if the boundary was matched, else returns the first byte + * from boundary + * @throws IOException + */ + private int matchForBoundary() throws IOException { + matchedCount = 0; + /* + * Going to "buffered mode". Read until full boundary match or a + * different character. + */ + while (true) { + matchedCount++; + if (matchedCount == boundary.length) { + /* + * The whole boundary matched so we have reached the end of + * file + */ + atTheEnd = true; + return -1; + } + int fromActualStream = realInputStream.read(); + if (fromActualStream != boundary[matchedCount]) { + /* + * Did not find full boundary, cache the mismatching byte + * and start returning the partially matched boundary. + */ + bufferedByte = fromActualStream; + return getBuffered(); + } + } + } + + /** * Returns the partly matched boundary string and the byte following * that. * @@ -2246,6 +2268,7 @@ public abstract class AbstractCommunicationManager implements // The boundary has been returned, return the buffered byte. b = bufferedByte; bufferedByte = -1; + matchedCount = -1; } else { b = boundary[curBoundaryIndex++]; if (curBoundaryIndex == matchedCount) { @@ -2266,7 +2289,7 @@ public abstract class AbstractCommunicationManager implements * boundaryString. This could be the start of the real * end boundary. */ - matchedCount = 1; + matchedCount = 0; bufferedByte = -1; } } |