class ProcessImplForWin32 extends Process {

    static Process start(String username,
                         String password,
                         String[] cmdarray,
                         java.util.Map<String,String> environment,
                         String dir,
                         ProcessBuilderForWin32.Redirect[] redirects,
                         boolean redirectErrorStream)
            throws IOException
    {
        String envblock = ProcessEnvironmentForWin32.toEnvironmentBlock(environment);

        FileInputStream  f0 = null;
        FileOutputStream f1 = null;
        FileOutputStream f2 = null;

        try {
            long[] stdHandles;
            if (redirects == null) {
                stdHandles = new long[] { -1L, -1L, -1L };
            } else {
                stdHandles = new long[3];

                if (redirects[0] == ProcessBuilderForWin32.Redirect.PIPE) {
                    stdHandles[0] = -1L;
                } else if (redirects[0] == ProcessBuilderForWin32.Redirect.INHERIT) {
                    stdHandles[0] = getHandle(FileDescriptor.in);
                } else {
                    f0 = new FileInputStream(redirects[0].file());
                    stdHandles[0] = getHandle(f0.getFD());
                }

                if (redirects[1] == ProcessBuilderForWin32.Redirect.PIPE) {
                    stdHandles[1] = -1L;
                } else if (redirects[1] == ProcessBuilderForWin32.Redirect.INHERIT) {
                    stdHandles[1] = getHandle(FileDescriptor.out);
                } else {
                    f1 = newFileOutputStream(redirects[1].file(),
                            redirects[1].append());
                    stdHandles[1] = getHandle(f1.getFD());
                }

                if (redirects[2] == ProcessBuilderForWin32.Redirect.PIPE) {
                    stdHandles[2] = -1L;
                } else if (redirects[2] == ProcessBuilderForWin32.Redirect.INHERIT) {
                    stdHandles[2] = getHandle(FileDescriptor.err);
                } else {
                    f2 = newFileOutputStream(redirects[2].file(),
                            redirects[2].append());
                    stdHandles[2] = getHandle(f2.getFD());
                }
            }

            return new ProcessImplForWin32(username, password, cmdarray, envblock, dir, stdHandles, redirectErrorStream);
        } finally {
            // In theory, close() can throw IOException
            // (although it is rather unlikely to happen here)
            try { if (f0 != null) {
                f0.close();
            }
            }
            finally {
                try { if (f1 != null) {
                    f1.close();
                }
                }
                finally { if (f2 != null) {
                    f2.close();
                }
                }
            }
        }

    }

    private  ProcessImplForWin32(
            String username,
            String password,
            String[] cmd,
            final String envblock,
            final String path,
            final long[] stdHandles,
            final boolean redirectErrorStream);

}