semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
void write() throws IOException {
        if (!allowUnlimitedArgs && args != null && args.length > 1) throw new IllegalArgumentException("Only one argument allowed unless allowUnlimitedArgs is enabled");
        String shebang = "#!" + interpretter;
        for (int i = 0; i < args.length; i++) {
            shebang += " " + args[i];
        }
        shebang += '\n';
        IOUtils.copy(new StringReader(shebang), outputStream);
    }
public static String digest(String pBase, String pCharSet) {
        String wdgs = null;
        try {
            MessageDigest wmd = MessageDigest.getInstance("MD5");
            wmd.reset();
            wmd.update(pBase.getBytes(pCharSet));
            byte[] wdg = wmd.digest();
            StringBuffer hexString = new StringBuffer();
            for (int i = 0; i < wdg.length; i++) {
                String w_dup = Integer.toHexString(0xFF & wdg[i]);
                if (w_dup.length() < 2) {
                    w_dup = "0" + w_dup;
                }
                hexString.append(w_dup);
            }
            wdgs = hexString.toString();
        } catch (NoSuchAlgorithmException ex) {
            ex.printStackTrace();
        } finally {
            return wdgs;
        }
    }
public static String getPagina(String strurl) {
        String resp = "";
        Authenticator.setDefault(new Autenticador());
        try {
            URL url = new URL(strurl);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String str;
            while ((str = in.readLine()) != null) {
                resp += str;
            }
            in.close();
        } catch (MalformedURLException e) {
            resp = e.toString();
        } catch (IOException e) {
            resp = e.toString();
        } catch (Exception e) {
            resp = e.toString();
        }
        return resp;
    }
public void maj(String titre, String num_version) {
        int res = 2;
        String content_xml = "";
        try {
            URL url = new URL("http://code.google.com/feeds/p/tux-team/downloads/basic");
            InputStreamReader ipsr = new InputStreamReader(url.openStream());
            BufferedReader br = new BufferedReader(ipsr);
            String line = null;
            StringBuffer buffer = new StringBuffer();
            while ((line = br.readLine()) != null) {
                buffer.append(line).append('\n');
            }
            br.close();
            content_xml = buffer.toString();
            res = lecture_xml(titre, num_version, content_xml);
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        switch(res) {
            case 0:
                ihm.jl_maj.setText("Pas de mises à jour disponible. (" + num_version + ")");
                ihm.jl_maj.setIcon(Resources.getImageIcon("images/valide.png", IHM_AProposDe.class));
                break;
            case 1:
                ihm.jl_maj.setText("Une mise à jour est diponible. (" + maj_file_version + ")");
                ihm.jl_maj.setIcon(Resources.getImageIcon("images/warning.png", IHM_AProposDe.class));
                ihm.jb_maj.setVisible(true);
                break;
            default:
                ihm.jl_maj.setText("Serveur de mise à jour non disponible.");
                ihm.jl_maj.setIcon(Resources.getImageIcon("images/erreur.png", IHM_AProposDe.class));
        }
    }
public Writer createWriter(File outfile, String encoding) throws UnsupportedEncodingException, IOException {
        int k_blockSize = 1024;
        int byteCount;
        char[] buf = new char[k_blockSize];
        ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(outfile));
        zos.setMethod(ZipOutputStream.DEFLATED);
        OutputStreamWriter osw = new OutputStreamWriter(zos, "ISO-8859-1");
        BufferedWriter bw = new BufferedWriter(osw);
        ZipEntry zot;
        ZipInputStream zis = new ZipInputStream(new FileInputStream(infile));
        InputStreamReader isr = new InputStreamReader(zis, "ISO-8859-1");
        BufferedReader br = new BufferedReader(isr);
        ZipEntry zit;
        while ((zit = zis.getNextEntry()) != null) {
            if (zit.getName().equals("content.xml")) {
                continue;
            }
            zot = new ZipEntry(zit.getName());
            zos.putNextEntry(zot);
            while ((byteCount = br.read(buf, 0, k_blockSize)) >= 0) bw.write(buf, 0, byteCount);
            bw.flush();
            zos.closeEntry();
        }
        zos.putNextEntry(new ZipEntry("content.xml"));
        bw.flush();
        return new OutputStreamWriter(zos, "UTF-8");
    }
public void restoreDrivers() throws ExplorerException {
        try {
            drivers.clear();
            URL url = URLUtil.getResourceURL("default_drivers.xml");
            loadDefaultDrivers(url.openStream());
        } catch (IOException e) {
            throw new ExplorerException(e);
        }
    }
public void performSearch(int searchStartIndex) {
        int index = 0;
        String searchString = keywords.getText();
        searchButton.setEnabled(false);
        if (!searchString.equals("")) {
            try {
                url = new URL(searchURL + "&num=" + maxReturns.getSelectedItem().toString() + "&start=" + searchStartIndex + "&q=" + searchString);
                System.out.println("Google search = " + url);
                InputStream input = url.openStream();
                int c;
                while ((c = input.read()) != -1) {
                    result = result + (char) c;
                }
                String googleResultsFile = VueUtil.getDefaultUserFolder().getAbsolutePath() + File.separatorChar + VueResources.getString("save.google.results");
                FileWriter fileWriter = new FileWriter(googleResultsFile);
                fileWriter.write(result);
                fileWriter.close();
                result = "";
                GSP gsp = loadGSP(googleResultsFile);
                Iterator i = gsp.getRES().getResultList().iterator();
                Vector resultVector = new Vector();
                while (i.hasNext()) {
                    Result r = (Result) i.next();
                    URLResource urlResource = new URLResource(r.getUrl());
                    if (r.getTitle() != null) urlResource.setTitle(r.getTitle().replaceAll("</*[a-zA-Z]>", "")); else urlResource.setTitle(r.getUrl().toString());
                    resultVector.add(urlResource);
                    System.out.println(r.getTitle() + " " + r.getUrl());
                }
                VueDragTree tree = new VueDragTree(resultVector.iterator(), "GoogleSearchResults");
                tree.setEditable(true);
                tree.setRootVisible(false);
                googleResultsPanel.remove(jsp);
                jsp = new JScrollPane(tree);
                JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 2, 0));
                bottomPanel.add(prevButton);
                bottomPanel.add(nextButton);
                googleResultsPanel.add(bottomPanel, BorderLayout.SOUTH);
                googleResultsPanel.add(jsp, BorderLayout.CENTER);
                googleResultsPanel.validate();
                googlePane.setSelectedComponent(googleResultsPanel);
            } catch (Exception ex) {
                System.out.println("cannot connect google");
                googleResultsPanel.remove(jsp);
                JPanel jp = new JPanel(new BorderLayout());
                jp.setBackground(Color.WHITE);
                JLabel jl = new JLabel("No Match Found");
                jp.add(jl, BorderLayout.NORTH);
                JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 2, 0));
                googleResultsPanel.add(jp, BorderLayout.CENTER);
                googleResultsPanel.validate();
                googlePane.setSelectedComponent(googleResultsPanel);
            }
        }
        searchButton.setEnabled(true);
    }
private static GSP loadGSP(URL url) {
        try {
            InputStream input = url.openStream();
            int c;
            while ((c = input.read()) != -1) {
                result = result + (char) c;
            }
            Unmarshaller unmarshaller = getUnmarshaller();
            unmarshaller.setValidation(false);
            GSP gsp = (GSP) unmarshaller.unmarshal(new InputSource());
            return gsp;
        } catch (Exception e) {
            System.out.println("loadGSP " + e);
            e.printStackTrace();
            return null;
        }
    }
public static void main(String[] args) throws Exception {
        if (args.length < 3) {
            usage(System.out);
            System.exit(1);
        }
        final File tmpFile = File.createTempFile("sej", null);
        tmpFile.deleteOnExit();
        final FileOutputStream destination = new FileOutputStream(tmpFile);
        final String mainClass = args[1];
        final Collection jars = new LinkedList();
        for (int i = 2; i < args.length; i++) {
            String arg = args[i];
            jars.add(arg);
        }
        JarInterpretted interpretted = new JarInterpretted(destination);
        JarCat rowr = new JarCat(destination, createManifest(mainClass), jars);
        interpretted.write();
        rowr.write();
        destination.close();
        final File finalDestinationFile = new File(args[0]);
        final FileOutputStream finalDestination = new FileOutputStream(finalDestinationFile);
        IOUtils.copy(new FileInputStream(tmpFile), finalDestination);
        finalDestination.close();
        Chmod chmod = new Chmod("a+rx", new File[] { finalDestinationFile });
        chmod.invoke();
    }
public static void copyFile(File src, File dst) throws IOException {
        FileChannel sourceChannel = new FileInputStream(src).getChannel();
        FileChannel destinationChannel = new FileOutputStream(dst).getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
        sourceChannel.close();
        destinationChannel.close();
    }
public int sftp_connect(HttpServletRequest request) {
        Map<String, Object> setting = (Map<String, Object>) request.getAttribute("globalSetting");
        int ftpssl = Common.intval(setting.get("ftpssl") + "");
        String ftphost = setting.get("ftphost") + "";
        int ftpport = Common.intval(setting.get("ftpport") + "");
        String ftpuser = setting.get("ftpuser") + "";
        String ftppassword = setting.get("ftppassword") + "";
        int ftppasv = Common.intval(setting.get("ftppasv") + "");
        String ftpdir = setting.get("ftpdir") + "";
        int ftptimeout = Common.intval(setting.get("ftptimeout") + "");
        if (ftpssl > 0) {
            try {
                fc = new FTPSClient();
            } catch (NoSuchAlgorithmException e) {
                e.printStackTrace();
                return JC_FTPClientException;
            }
        } else {
            fc = new FTPClient();
        }
        try {
            fc.setConnectTimeout(20000);
            InetAddress inetAddress = InetAddress.getByName(ftphost);
            fc.connect(inetAddress, ftpport);
            if (fc.login(ftpuser, ftppassword)) {
                if (ftppasv > 0) {
                    fc.pasv();
                }
                if (ftptimeout > 0) {
                    fc.setDataTimeout(ftptimeout);
                }
                if (fc.changeWorkingDirectory(ftpdir)) {
                    return JC_FTPClientYES;
                } else {
                    FileHelper.writeLog(request, "FTP", "CHDIR " + ftpdir + " ERROR.");
                    try {
                        fc.disconnect();
                        fc = null;
                    } catch (Exception e1) {
                    }
                    return JC_FTPClientNO;
                }
            } else {
                FileHelper.writeLog(request, "FTP", "530 NOT LOGGED IN.");
                try {
                    fc.disconnect();
                    fc = null;
                } catch (Exception e1) {
                }
                return JC_FTPClientNO;
            }
        } catch (Exception e) {
            FileHelper.writeLog(request, "FTP", "COULDN'T CONNECT TO " + ftphost + ":" + ftpport + ".");
            e.printStackTrace();
            if (fc != null) {
                try {
                    fc.disconnect();
                    fc = null;
                } catch (Exception e1) {
                }
            }
            return JC_FTPClientException;
        }
    }
private InputStream createInputStream(String url) throws MalformedURLException, IOException {
        if (url.startsWith("classpath://")) {
            InputStream is = XMLResource.class.getResourceAsStream(url.substring(12));
            if (is == null) throw new IOException("Couldn't open stream to [" + url + "]");
            return is;
        } else {
            return new URL(url).openStream();
        }
    }
public void store(String path, InputStream stream) throws IOException {
        toIgnore.add(normalizePath(path));
        ZipEntry entry = new ZipEntry(path);
        zipOutput.putNextEntry(entry);
        IOUtils.copy(stream, zipOutput);
        zipOutput.closeEntry();
    }
private void copyEntries() {
        if (zipFile != null) {
            Enumeration<? extends ZipEntry> enumerator = zipFile.entries();
            while (enumerator.hasMoreElements()) {
                ZipEntry entry = enumerator.nextElement();
                if (!entry.isDirectory() && !toIgnore.contains(normalizePath(entry.getName()))) {
                    ZipEntry originalEntry = new ZipEntry(entry.getName());
                    try {
                        zipOutput.putNextEntry(originalEntry);
                        IOUtils.copy(getInputStream(entry.getName()), zipOutput);
                        zipOutput.closeEntry();
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
public InputStream openInput(Fragment path) throws IOException {
        int len = path.words().size();
        String p = Util.combine("/", path.words().subList(1, len));
        URL url = new URL("http", path.words().get(0), p);
        InputStream result = url.openStream();
        return result;
    }
static File copy(File in, File out) throws IOException {
        FileChannel inChannel = new FileInputStream(in).getChannel();
        FileChannel outChannel = new FileOutputStream(out).getChannel();
        try {
            inChannel.transferTo(0, inChannel.size(), outChannel);
            return out;
        } catch (IOException e) {
            throw e;
        } finally {
            if (inChannel != null) inChannel.close();
            if (outChannel != null) outChannel.close();
        }
    }
private String storeProxy(String proxyPath, String userName) throws IOException {
        File inputFile = new File(proxyPath);
        String outfile = slcsFactory.getStoreDirectory() + File.separator + userName + File.separator + PROXYFILENAME;
        File outputFile = new File(outfile);
        FileReader in = new FileReader(inputFile);
        FileWriter out = new FileWriter(outputFile);
        int c;
        while ((c = in.read()) != -1) out.write(c);
        in.close();
        out.close();
        Process p = Runtime.getRuntime().exec("/bin/chmod 600 " + outfile);
        try {
            p.waitFor();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return outfile;
    }
protected String getPageText(final String url) {
        StringBuilder b = new StringBuilder();
        BufferedReader reader = null;
        try {
            reader = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
            String line = null;
            while ((line = reader.readLine()) != null) {
                b.append(line).append('\n');
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException ex) {
                    ex.printStackTrace();
                }
            }
        }
        return b.toString();
    }
public static void copy(File srcPath, File dstPath) throws IOException {
        if (srcPath.isDirectory()) {
            if (!dstPath.exists()) {
                boolean result = dstPath.mkdir();
                if (!result) throw new IOException("Unable to create directoy: " + dstPath);
            }
            String[] files = srcPath.list();
            for (String file : files) {
                copy(new File(srcPath, file), new File(dstPath, file));
            }
        } else {
            if (srcPath.exists()) {
                FileChannel in = null;
                FileChannel out = null;
                try {
                    in = new FileInputStream(srcPath).getChannel();
                    out = new FileOutputStream(dstPath).getChannel();
                    long size = in.size();
                    MappedByteBuffer buf = in.map(FileChannel.MapMode.READ_ONLY, 0, size);
                    out.write(buf);
                } finally {
                    if (in != null) in.close();
                    if (out != null) out.close();
                }
            }
        }
    }
public static byte[] readUrl(URL url) {
        BufferedInputStream in = null;
        try {
            class Part {

                byte[] partData;

                int len;
            }
            in = new BufferedInputStream(url.openStream());
            LinkedList<Part> parts = new LinkedList<Part>();
            int len = 1;
            while (len > 0) {
                byte[] data = new byte[1024];
                len = in.read(data);
                if (len > 0) {
                    Part part = new Part();
                    part.partData = data;
                    part.len = len;
                    parts.add(part);
                }
            }
            int length = 0;
            for (Part part : parts) length += part.len;
            byte[] result = new byte[length];
            int pos = 0;
            for (Part part : parts) {
                System.arraycopy(part.partData, 0, result, pos, part.len);
                pos += part.len;
            }
            return result;
        } catch (IOException e) {
            return null;
        } finally {
            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                }
            }
        }
    }
public static String base64HashedString(String v) {
        String base64HashedPassword = null;
        try {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(v.getBytes());
            String hashedPassword = new String(md.digest());
            sun.misc.BASE64Encoder enc = new sun.misc.BASE64Encoder();
            base64HashedPassword = enc.encode(hashedPassword.getBytes());
        } catch (java.security.NoSuchAlgorithmException e) {
            throw new NSForwardException(e, "Couldn't find the SHA hash algorithm; perhaps you do not have the SunJCE security provider installed properly?");
        }
        return base64HashedPassword;
    }
private String getMD5Hash(String password) {
        String plainText = password;
        MessageDigest mdAlgorithm;
        StringBuffer hexString = new StringBuffer();
        try {
            mdAlgorithm = MessageDigest.getInstance("MD5");
            mdAlgorithm.update(plainText.getBytes());
            byte[] digest = mdAlgorithm.digest();
            for (int i = 0; i < digest.length; i++) {
                plainText = Integer.toHexString(0xFF & digest[i]);
                if (plainText.length() < 2) {
                    plainText = "0" + plainText;
                }
                hexString.append(plainText);
            }
        } catch (NoSuchAlgorithmException ex) {
            ex.printStackTrace();
        }
        return hexString.toString();
    }
public boolean backupLastAuditSchema(File lastAuditSchema) {
        boolean isBkupFileOK = false;
        String writeTimestamp = DateFormatUtils.format(new java.util.Date(), configFile.getTimestampPattern());
        File target = new File(configFile.getAuditSchemaFileDir() + File.separator + configFile.getAuditSchemaFileName() + ".bkup_" + writeTimestamp);
        FileChannel sourceChannel = null;
        FileChannel targetChannel = null;
        try {
            sourceChannel = new FileInputStream(lastAuditSchema).getChannel();
            targetChannel = new FileOutputStream(target).getChannel();
            targetChannel.transferFrom(sourceChannel, 0, sourceChannel.size());
        } catch (IOException e) {
            logger.log(Level.SEVERE, "IO exception occurred while copying file", e);
        } finally {
            if ((target != null) && (target.exists()) && (target.length() > 0)) {
                isBkupFileOK = true;
            }
            try {
                if (sourceChannel != null) {
                    sourceChannel.close();
                }
                if (targetChannel != null) {
                    targetChannel.close();
                }
            } catch (IOException e) {
                logger.info("closing channels failed");
            }
        }
        return isBkupFileOK;
    }
private void native2ascii(LanguageInfo info) {
        if (!info.isUTF8()) throw new IllegalArgumentException("requires utf8 language.");
        InputStream in = null;
        OutputStream out = null;
        print("\tConverting to ASCII... ");
        try {
            in = new BufferedInputStream(new FileInputStream(info.getFileName()));
            in.mark(3);
            if (in.read() != 0xEF || in.read() != 0xBB || in.read() != 0xBF) in.reset();
            BufferedReader reader = new BufferedReader(new InputStreamReader(in, "UTF8"));
            out = new BufferedOutputStream(new FileOutputStream(info.getAlternateFileName()));
            BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(out, "ISO-8859-1"));
            String read;
            while ((read = reader.readLine()) != null) {
                writer.write(ascii(read));
                writer.newLine();
            }
            writer.flush();
            out.flush();
            println("... done!");
        } catch (IOException ignored) {
            println("... error! (" + ignored.getMessage() + ")");
        } finally {
            if (in != null) try {
                in.close();
            } catch (IOException ignored) {
            }
            if (out != null) try {
                out.close();
            } catch (IOException ignored) {
            }
        }
    }
private void writeMessage(ChannelBuffer buffer, File dst) throws IOException {
        ChannelBufferInputStream is = new ChannelBufferInputStream(buffer);
        OutputStream os = null;
        try {
            os = new FileOutputStream(dst);
            IOUtils.copyLarge(is, os);
        } finally {
            IOUtils.closeQuietly(os);
        }
    }
public static String getMD5(final String data) {
        try {
            MessageDigest m = MessageDigest.getInstance("MD5");
            m.reset();
            m.update(data.getBytes());
            BigInteger bigInt = new BigInteger(1, m.digest());
            String hashtext = bigInt.toString(16);
            while (hashtext.length() < 32) {
                hashtext = "0" + hashtext;
            }
            return hashtext;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
            return e.getMessage();
        }
    }