Created
December 18, 2012 12:45
-
-
Save grimrose/4327662 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
#!/bin/bash | |
echo 'convert start.' | |
noise_option="$1" | |
if [ -z $noise_option ]; then | |
noise_option=0 | |
fi | |
echo "noise_option: [$noise_option]" | |
if [ -e irof.html ]; then | |
rm irof.html | |
fi | |
java -jar jitac-0.2.0.jar -H -o irof.html -n $noise_option irof.jpeg | |
if [ -e irof.html ]; then | |
echo "convert success!" | |
fi | |
exit 0 |
This file contains hidden or 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
import com.sun.net.httpserver.HttpExchange | |
import com.sun.net.httpserver.HttpHandler | |
import com.sun.net.httpserver.HttpServer | |
class Converter { | |
void convert(int parcent = 0) { | |
def process = "./convert.sh ${parcent/100}".execute() | |
println "${process.text}" | |
} | |
} | |
def PORT = 9000 | |
HttpServer server = HttpServer.create(new InetSocketAddress(PORT), 0) | |
server.createContext('/', new HttpHandler() { | |
@Override | |
public void handle(HttpExchange exchange) throws IOException { | |
def noise = [ 0, 10, 20] | |
def random = new Random().nextInt(noise.size) | |
new Converter().convert(noise[random]) | |
def file = new File('irof.html') | |
assert file.canRead() | |
def bytes = file.text.bytes | |
exchange.getResponseHeaders().add("Content-Type", "text/html") | |
exchange.sendResponseHeaders(200, bytes.length) | |
exchange.getResponseBody().write(bytes) | |
exchange.close() | |
} | |
}) | |
server.start() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment