Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started work on accepting octet streams
Made the first pass at getting the services to accept octet stream input. Signed-off-by: Robert Smith <smithrw@ornl.gov>
- Loading branch information
1 parent
a88ad38
commit f5bf378
Showing
4 changed files
with
84 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
org.eclipse.eavp.micro/src/org/eclipse/eavp/micro/main/java/InputStreamUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/******************************************************************************* | ||
* Copyright (c) 2019 UT-Battelle, LLC. | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
* | ||
* Contributors: | ||
* Robert Smith | ||
*******************************************************************************/ | ||
package org.eclipse.eavp.micro.main.java; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.InputStreamReader; | ||
import java.io.UnsupportedEncodingException; | ||
import java.util.ArrayList; | ||
|
||
/** | ||
* Utility functions for dealing with input streams | ||
* | ||
* @author Robert Smith | ||
* | ||
*/ | ||
public class InputStreamUtils { | ||
|
||
/** | ||
* Read a full text stream from the input stream | ||
* | ||
* @param stream The stream to read. | ||
* @return The string formed from the stream. | ||
*/ | ||
public static String readStringStream(InputStream stream) { | ||
|
||
//Buffer to hold chunks of the stream | ||
char[] buffer = new char[1024]; | ||
|
||
//String builder that will hold the contents | ||
StringBuilder builder = new StringBuilder(); | ||
|
||
try { | ||
|
||
//Create a reader for the stream | ||
InputStreamReader reader = new InputStreamReader(stream, "UTF-8"); | ||
|
||
//Loop until the stream is exhausted, adding all content to the builder | ||
int size = reader.read(buffer, 0, 1024); | ||
|
||
while(size >= 0) { | ||
builder.append(buffer, 0, size); | ||
size = reader.read(buffer, 0, 1024); | ||
} | ||
|
||
} catch (IOException e) { | ||
// TODO Auto-generated catch block | ||
e.printStackTrace(); | ||
} | ||
|
||
return builder.toString(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters