From ac7ebc90da4ac6e80b3925e9aac18d1c6ff4d491 Mon Sep 17 00:00:00 2001 From: David Kuettel Date: Wed, 10 Apr 2013 15:16:04 -0700 Subject: [PATCH] Cleanup: remove unused Command abstractions --- .../typography/font/compression/Command.java | 72 ------------------- .../font/compression/CommandException.java | 12 ---- .../font/compression/CommandResult.java | 18 ----- .../font/compression/TestCommand.java | 28 -------- 4 files changed, 130 deletions(-) delete mode 100644 src/com/google/typography/font/compression/Command.java delete mode 100644 src/com/google/typography/font/compression/CommandException.java delete mode 100644 src/com/google/typography/font/compression/CommandResult.java delete mode 100644 src/com/google/typography/font/compression/TestCommand.java diff --git a/src/com/google/typography/font/compression/Command.java b/src/com/google/typography/font/compression/Command.java deleted file mode 100644 index 6b11f31..0000000 --- a/src/com/google/typography/font/compression/Command.java +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright 2011 Google Inc. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package com.google.typography.font.compression; - -import com.google.common.io.ByteStreams; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; - -/** - * This is a simple wrapper to run a commandline as a pipe. It's not - * particularly efficient, robust, or featureful. - */ -public class Command { - - private class StreamConsumer extends Thread { - private final InputStream is; - private byte[] result = null; - - public StreamConsumer(InputStream is) { - this.is = is; - } - - @Override - public void run() { - try { - result = ByteStreams.toByteArray(is); - } catch (IOException e) { - // TODO: handle this well - } - } - - public byte[] getResult() { - return result; - } - } - - private final ProcessBuilder processBuilder; - - public Command(String[] args) { - processBuilder = new ProcessBuilder(args); - } - - public CommandResult execute(byte[] input) throws CommandException { - Process process; - try { - process = processBuilder.start(); - } catch (IOException e) { - throw new CommandException("exec failed"); - } - StreamConsumer sc = new StreamConsumer(process.getInputStream()); - sc.start(); - OutputStream stdin = process.getOutputStream(); - try { - stdin.write(input); - stdin.close(); - } catch (IOException e) { - throw new CommandException("error writing input"); - } - try { - process.waitFor(); - sc.join(); - } catch (InterruptedException e) { - throw new CommandException("interrupted"); - } - return new CommandResult(sc.getResult()); - } -} - diff --git a/src/com/google/typography/font/compression/CommandException.java b/src/com/google/typography/font/compression/CommandException.java deleted file mode 100644 index 9f9125f..0000000 --- a/src/com/google/typography/font/compression/CommandException.java +++ /dev/null @@ -1,12 +0,0 @@ -// Copyright 2011 Google Inc. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package com.google.typography.font.compression; - -public class CommandException extends Exception { - public CommandException(String message) { - super(message); - } -} - diff --git a/src/com/google/typography/font/compression/CommandResult.java b/src/com/google/typography/font/compression/CommandResult.java deleted file mode 100644 index 4f1e787..0000000 --- a/src/com/google/typography/font/compression/CommandResult.java +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright 2011 Google Inc. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package com.google.typography.font.compression; - -public final class CommandResult { - private final byte[] stdout; - - public CommandResult(byte[] stdout) { - this.stdout = stdout; - } - - public byte[] getStdout() { - return stdout; - } -} - diff --git a/src/com/google/typography/font/compression/TestCommand.java b/src/com/google/typography/font/compression/TestCommand.java deleted file mode 100644 index d527f6b..0000000 --- a/src/com/google/typography/font/compression/TestCommand.java +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright 2011 Google Inc. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package com.google.typography.font.compression; - -import java.io.IOException; - -/** - * A simple test for the command mechanism. Quick and dirty run with: - * java -cp 'build/classes:lib/guava-11.0.1.jar' com/google/typography/font/compression/TestCommand - */ -public class TestCommand { - public static void main(String[] args) throws IOException { - String[] commandArgs = {"/usr/bin/lzma"}; - byte[] input = new byte[16384]; - try { - CommandResult result = new Command(commandArgs).execute(input); - byte[] output = result.getStdout(); - for (int i = 0; i < output.length; i++) { - System.out.printf("%02x\n", output[i] & 0xff); - } - } catch (CommandException e) { - e.printStackTrace(); - }; - } -} -