semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
@Override
    public void executeInterruptible() {
        EncodeFilesDialog dialog = (EncodeFilesDialog) this.dialog;
        File encoderFile = null;
        InputStream is = null;
        OutputStream os = null;
        try {
            if (Platform.isWindows()) {
                encoderFile = new File(".", "lame.exe");
                is = Thread.currentThread().getContextClassLoader().getResourceAsStream("lame/lame.exe");
            } else if (Platform.isLinux()) {
                encoderFile = new File(".", "lame");
                is = Thread.currentThread().getContextClassLoader().getResourceAsStream("lame/lame");
            } else {
                MainWindowInterface.showError(new Exception(Messages.getString("operations.file.encode.dialog.notsupported")));
                return;
            }
            os = new FileOutputStream(encoderFile);
            IOUtils.copy(is, os);
        } catch (Exception e) {
            LOG.error("Cannot extract encoder executable", e);
            MainWindowInterface.showError(e);
            return;
        } finally {
            IOUtils.closeQuietly(is);
            IOUtils.closeQuietly(os);
        }
        encoderFile.setExecutable(true, true);
        try {
            long totalSize = 0l;
            for (int i = 0, l = filesModel.getSize(); i < l; i++) {
                if (isInterrupted()) return;
                IconAndFileListElement element = (IconAndFileListElement) filesModel.get(i);
                File origFile = element.getFile();
                totalSize += origFile.length();
            }
            rangeModel = dialog.getProgressBar().getModel();
            rangeModel.setMinimum(0);
            rangeModel.setMaximum((int) totalSize);
            int parallelProcesses = dialog.getParallelProcesses();
            List<Thread> encodingThreads = new ArrayList<Thread>();
            encodingRunnables = new ArrayList<EncoderLauncherRunnable>(parallelProcesses);
            for (int i = 0; i < parallelProcesses; i++) {
                EncoderLauncherRunnable encoderLauncherRunnable = new EncoderLauncherRunnable(i, dialog, encoderFile);
                Thread thread = new Thread(encoderLauncherRunnable);
                encodingRunnables.add(encoderLauncherRunnable);
                encodingThreads.add(thread);
                thread.start();
            }
            for (Thread thread : encodingThreads) {
                thread.join();
            }
            if (!isInterrupted()) MainWindowInterface.showMessage(Messages.getString("operations.file.encode.execute.done.title"), Messages.getString("operations.file.encode.execute.done.message").replace("${number}", "" + filesModel.getSize()));
        } catch (Exception e) {
            LOG.error("Cannot encode files", e);
            MainWindowInterface.showError(e);
        } finally {
            if (encoderFile != null) encoderFile.delete();
            dialog.setVisible(false);
        }
    }
public static String[] readStats() throws Exception {
        URL url = null;
        BufferedReader reader = null;
        StringBuilder stringBuilder;
        try {
            url = new URL("http://localhost:" + port + webctx + "/shared/js/libOO/health_check.sjs");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("GET");
            connection.setReadTimeout(10 * 1000);
            connection.connect();
            reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            stringBuilder = new StringBuilder();
            String line = null;
            while ((line = reader.readLine()) != null) {
                stringBuilder.append(line);
            }
            return stringBuilder.toString().split(",");
        } catch (Exception e) {
            e.printStackTrace();
            throw e;
        } finally {
            if (reader != null) {
                try {
                    reader.close();
                } catch (IOException ioe) {
                    ioe.printStackTrace();
                }
            }
        }
    }
public static String downloadJar(URL url) throws IOException {
        String localFile = null;
        char[] buf = new char[4096];
        int num;
        localFile = Settings.getFreeTsUserPath() + "lib" + Settings.SLASH + getURLFileName(url);
        DebugDialog.print("Downloading jar-file " + url + " to " + localFile + ".", 4);
        InputStreamReader in = new InputStreamReader(url.openStream());
        OutputStreamWriter out = new OutputStreamWriter(new FileOutputStream(localFile));
        do {
            num = in.read(buf, 0, 4096);
            if (num > 0) {
                out.write(buf, 0, num);
            }
        } while (num > 0);
        in.close();
        out.close();
        return localFile;
    }
private StylingEngine createStyling() {
        StylingFactory stylingFactory = StylingFactory.getDefaultInstance();
        StyleSheetCompilerFactory inlineCompilerFactory = new InlineStyleSheetCompilerFactory(null);
        StylingEngine stylingEngine = stylingFactory.createStylingEngine(inlineCompilerFactory);
        CSSCompilerBuilder builder = new CSSCompilerBuilder();
        builder.setStyleSheetCompilerFactory(DefaultStyleSheetCompilerFactory.getDefaultInstance());
        CSSCompiler cssCompiler = builder.getCSSCompiler();
        CompiledStyleSheet defaultCompiledStyleSheet;
        try {
            URL url = getClass().getResource("/com/volantis/mcs/runtime/default.css");
            InputStream stream = url.openStream();
            defaultCompiledStyleSheet = cssCompiler.compile(new InputStreamReader(stream), null);
        } catch (IOException e) {
            throw new ExtendedRuntimeException(e);
        }
        stylingEngine.pushStyleSheet(defaultCompiledStyleSheet);
        if (protocol != null && protocol.getCompiledDefaultStyleSheet() != null) {
            stylingEngine.pushStyleSheet(protocol.getCompiledDefaultStyleSheet());
        }
        return stylingEngine;
    }
private String MD5(String s) {
        Log.d("MD5", "Hashing '" + s + "'");
        String hash = "";
        try {
            MessageDigest m = MessageDigest.getInstance("MD5");
            m.update(s.getBytes(), 0, s.length());
            hash = new BigInteger(1, m.digest()).toString(16);
            Log.d("MD5", "Hash: " + hash);
        } catch (Exception e) {
            Log.e("MD5", e.getMessage());
        }
        return hash;
    }
public static void main(String[] args) throws IOException, ClassNotFoundException {
        URL urlServlet = null;
        try {
            urlServlet = new URL("http://wofproj.appspot.com/test");
        } catch (MalformedURLException e) {
            e.printStackTrace();
        }
        URLConnection con = null;
        try {
            con = urlServlet.openConnection();
        } catch (IOException e) {
            e.printStackTrace();
        }
        con.setDoInput(true);
        con.setDoOutput(true);
        con.setUseCaches(false);
        con.setRequestProperty("Content-Type", "application/x-java-serialized-object");
        OutputStream outstream = con.getOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(outstream);
        oos.writeObject("tom");
        oos.flush();
        oos.close();
        InputStream instr = con.getInputStream();
        ObjectInputStream inputFromServlet = new ObjectInputStream(instr);
        Object retval = inputFromServlet.readObject();
        inputFromServlet.close();
        instr.close();
        System.out.println(retval.getClass().toString());
    }
public void testGetRequestWithRefresh() throws Exception {
        expect(request.getParameter(ProxyBase.REFRESH_PARAM)).andReturn("120").anyTimes();
        Capture<HttpRequest> requestCapture = new Capture<HttpRequest>();
        expect(pipeline.execute(capture(requestCapture))).andReturn(new HttpResponse(RESPONSE_BODY));
        replay();
        handler.fetch(request, recorder);
        HttpRequest httpRequest = requestCapture.getValue();
        assertEquals("public,max-age=120", recorder.getHeader("Cache-Control"));
        assertEquals(120, httpRequest.getCacheTtl());
    }
public void testExplicitHeaders() throws Exception {
        String headerString = "X-Foo=bar&X-Bar=baz%20foo";
        HttpRequest expected = new HttpRequest(REQUEST_URL).addHeader("X-Foo", "bar").addHeader("X-Bar", "baz foo");
        expect(pipeline.execute(expected)).andReturn(new HttpResponse(RESPONSE_BODY));
        expect(request.getParameter(MakeRequestHandler.HEADERS_PARAM)).andReturn(headerString);
        replay();
        handler.fetch(request, recorder);
        verify();
        JSONObject results = extractJsonFromResponse();
        assertEquals(HttpResponse.SC_OK, results.getInt("rc"));
        assertEquals(RESPONSE_BODY, results.get("body"));
        assertTrue(rewriter.responseWasRewritten());
    }
public void play() throws FileNotFoundException, IOException, NoSuchAlgorithmException, FTPException {
        final int BUFFER = 2048;
        String host = "ftp.genome.jp";
        String username = "anonymous";
        String password = "";
        FTPClient ftp = null;
        ftp = new FTPClient();
        ftp.setRemoteHost(host);
        FTPMessageCollector listener = new FTPMessageCollector();
        ftp.setMessageListener(listener);
        System.out.println("Connecting");
        ftp.connect();
        System.out.println("Logging in");
        ftp.login(username, password);
        System.out.println("Setting up passive, ASCII transfers");
        ftp.setConnectMode(FTPConnectMode.PASV);
        ftp.setType(FTPTransferType.ASCII);
        System.out.println("Directory before put:");
        String[] files = ftp.dir(".", true);
        for (int i = 0; i < files.length; i++) System.out.println(files[i]);
        System.out.println("Quitting client");
        ftp.quit();
        String messages = listener.getLog();
        System.out.println("Listener log:");
        System.out.println(messages);
        System.out.println("Test complete");
    }
public static void testMapSource(MapSource mapSource, EastNorthCoordinate coordinate) throws Exception {
        int zoom = mapSource.getMaxZoom();
        MapSpace mapSpace = mapSource.getMapSpace();
        int tilex = mapSpace.cLonToX(coordinate.lon, zoom) / mapSpace.getTileSize();
        int tiley = mapSpace.cLatToY(coordinate.lat, zoom) / mapSpace.getTileSize();
        URL url = new URL(mapSource.getTileUrl(zoom, tilex, tiley));
        HttpURLConnection c = (HttpURLConnection) url.openConnection();
        c.connect();
        c.disconnect();
        if (c.getResponseCode() != 200) throw new MapSourceTestFailed(mapSource, c.getResponseCode());
    }
public int updatewuliao(Addwuliao aw) {
        int flag = 0;
        Connection conn = null;
        PreparedStatement pm = null;
        try {
            conn = Pool.getConnection();
            conn.setAutoCommit(false);
            pm = conn.prepareStatement("update addwuliao set inname=?,innum=?,inprice=?,productsdetail=?where pid=?");
            pm.setString(1, aw.getInname());
            pm.setInt(2, aw.getInnum());
            pm.setDouble(3, aw.getInprice());
            pm.setString(4, aw.getProductsdetail());
            pm.setString(5, aw.getPid());
            flag = pm.executeUpdate();
            conn.commit();
            Pool.close(pm);
            Pool.close(conn);
        } catch (Exception e) {
            e.printStackTrace();
            try {
                conn.rollback();
            } catch (Exception ep) {
                ep.printStackTrace();
            }
            Pool.close(pm);
            Pool.close(conn);
        } finally {
            Pool.close(pm);
            Pool.close(conn);
        }
        return flag;
    }
public static void copyFile(String pathOrig, String pathDst) throws FileNotFoundException, IOException {
        InputStream in;
        OutputStream out;
        if (pathOrig == null || pathDst == null) {
            System.err.println("Error en path");
            return;
        }
        File orig = new File(pathOrig);
        if (!orig.exists() || !orig.isFile() || !orig.canRead()) {
            System.err.println("Error en fichero de origen");
            return;
        }
        File dest = new File(pathDst);
        String file = new File(pathOrig).getName();
        if (dest.isDirectory()) pathDst += file;
        in = new FileInputStream(pathOrig);
        out = new FileOutputStream(pathDst);
        byte[] buf = new byte[1024];
        int len;
        while ((len = in.read(buf)) > 0) out.write(buf, 0, len);
        in.close();
        out.close();
    }
public void run() {
        FileInputStream src;
        try {
            src = new FileInputStream(srcName);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
            return;
        }
        FileOutputStream dest;
        FileChannel srcC = src.getChannel();
        ByteBuffer buf = ByteBuffer.allocateDirect(BUFFER_SIZE);
        try {
            int i = 1;
            int fileNo = 0;
            long maxByte = this.maxSize << 10;
            long nbByte = srcC.size();
            long nbFile = (nbByte / maxByte) + 1;
            for (fileNo = 0; fileNo < nbFile; fileNo++) {
                long fileByte = 0;
                String destName = srcName + "_" + fileNo;
                dest = new FileOutputStream(destName);
                FileChannel destC = dest.getChannel();
                while ((i > 0) && fileByte < maxByte) {
                    i = srcC.read(buf);
                    buf.flip();
                    fileByte += i;
                    destC.write(buf);
                    buf.compact();
                }
                destC.close();
                dest.close();
            }
        } catch (IOException e1) {
            e1.printStackTrace();
            return;
        }
    }
public static void copyFile(File src, String srcEncoding, File dest, String destEncoding) throws IOException {
        InputStreamReader in = new InputStreamReader(new FileInputStream(src), srcEncoding);
        OutputStreamWriter out = new OutputStreamWriter(new RobustFileOutputStream(dest), destEncoding);
        int c;
        while ((c = in.read()) != -1) out.write(c);
        out.flush();
        in.close();
        out.close();
    }
private static boolean DownloadDB() {
        URL url = null;
        BufferedWriter inWriter = null;
        String line;
        try {
            url = new URL(URL);
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream(), "UTF-8"));
            inWriter = new BufferedWriter(new FileWriter(InFileName));
            while ((line = reader.readLine()) != null) {
                inWriter.write(line);
                inWriter.newLine();
            }
            inWriter.close();
        } catch (Exception e) {
            try {
                inWriter.close();
            } catch (IOException ignored) {
            }
            e.printStackTrace();
            return false;
        }
        return true;
    }
private void copyResources(File oggDecDir, String[] resources, String resPrefix) throws FileNotFoundException, IOException {
        for (int i = 0; i < resources.length; i++) {
            String res = resPrefix + resources[i];
            InputStream is = this.getClass().getResourceAsStream(res);
            if (is == null) throw new IllegalArgumentException("cannot find resource '" + res + "'");
            File file = new File(oggDecDir, resources[i]);
            if (!file.exists() || file.length() == 0) {
                FileOutputStream fos = new FileOutputStream(file);
                try {
                    IOUtils.copyStreams(is, fos);
                } finally {
                    fos.close();
                }
            }
        }
    }
private static byte[] Md5f(String plainText) {
        byte[] ab = new byte[16];
        try {
            MessageDigest md = MessageDigest.getInstance("MD5");
            md.update(plainText.getBytes());
            byte b[] = md.digest();
            ab = b;
        } catch (NoSuchAlgorithmException e) {
            e.printStackTrace();
        }
        return ab;
    }
private String getResultFromHttpUrl(String href) {
        String result = null;
        try {
            URL url = new URL(href);
            HttpURLConnection conn = (HttpURLConnection) url.openConnection();
            Object o = conn.getContent();
            log.debug("Opened " + href + " and got class " + o.getClass().getName());
            StringBuffer version = new StringBuffer();
            String inputLine;
            DataInputStream dis = new DataInputStream(conn.getInputStream());
            while ((inputLine = dis.readLine()) != null) {
                version.append(inputLine + "\n");
            }
            result = version.toString();
            log.debug("Read from URL:\n" + result);
            dis.close();
        } catch (Exception e) {
            log.debug("Caught exception " + e + " whilst attempting to query URL " + href);
            e.printStackTrace();
        } finally {
            return result;
        }
    }
public static String getContent(String path, String encoding) throws IOException {
        URL url = new URL(path);
        URLConnection conn = url.openConnection();
        conn.setDoOutput(true);
        InputStream inputStream = conn.getInputStream();
        InputStreamReader isr = new InputStreamReader(inputStream, encoding);
        StringBuffer sb = new StringBuffer();
        BufferedReader in = new BufferedReader(isr);
        String inputLine;
        while ((inputLine = in.readLine()) != null) {
            sb.append(inputLine);
            sb.append("\n");
        }
        return sb.toString();
    }
public String getTemplateString(String templateFilename) {
        InputStream is = servletContext.getResourceAsStream("/resources/" + templateFilename);
        StringWriter writer = new StringWriter();
        try {
            IOUtils.copy(is, writer);
        } catch (IOException e) {
            e.printStackTrace();
        }
        return writer.toString();
    }
protected void copy(URL url, File file) throws IOException {
        InputStream in = null;
        FileOutputStream out = null;
        try {
            in = url.openStream();
            out = new FileOutputStream(file);
            IOUtils.copy(in, out);
        } finally {
            if (out != null) {
                out.close();
            }
            if (in != null) {
                in.close();
            }
        }
    }
public static void main(String[] args) throws Exception {
        String codecClassname = args[0];
        Class<?> codecClass = Class.forName(codecClassname);
        Configuration conf = new Configuration();
        CompressionCodec codec = (CompressionCodec) ReflectionUtils.newInstance(codecClass, conf);
        Compressor compressor = null;
        try {
            compressor = CodecPool.getCompressor(codec);
            CompressionOutputStream out = codec.createOutputStream(System.out, compressor);
            IOUtils.copyBytes(System.in, out, 4096, false);
            out.finish();
        } finally {
            CodecPool.returnCompressor(compressor);
        }
    }
public static String test(String server, String baseDir, String user, String password) throws Exception {
        FTPClient ftpClient = new FTPClient();
        try {
            String file = baseDir;
            ftpClient.connect(server);
            ftpClient.login(user, password);
            int reply = ftpClient.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftpClient.disconnect();
                System.err.println("FTP server refused connection.");
                return null;
            }
            ftpClient.setFileType(FTP.IMAGE_FILE_TYPE);
            ftpClient.enterLocalPassiveMode();
            boolean isDir = isDir(ftpClient, file);
            if (isDir) {
                FTPFile[] files = ftpClient.listFiles(file);
                for (int i = 0; i < files.length; i++) {
                }
            } else {
                ByteArrayOutputStream bos = new ByteArrayOutputStream();
                if (ftpClient.retrieveFile(file, bos)) {
                } else {
                    throw new IOException("Unable to retrieve file:" + file);
                }
            }
            return "";
        } finally {
            closeConnection(ftpClient);
        }
    }
private FTPClient getFtpClient(Entry parentEntry) throws Exception {
        Object[] values = parentEntry.getValues();
        if (values == null) {
            return null;
        }
        String server = (String) values[COL_SERVER];
        String baseDir = (String) values[COL_BASEDIR];
        String user = (String) values[COL_USER];
        String password = (String) values[COL_PASSWORD];
        if (password != null) {
            password = getRepository().getPageHandler().processTemplate(password, false);
        } else {
            password = "";
        }
        FTPClient ftpClient = new FTPClient();
        try {
            ftpClient.connect(server);
            if (user != null) {
                ftpClient.login(user, password);
            }
            int reply = ftpClient.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftpClient.disconnect();
                System.err.println("FTP server refused connection.");
                return null;
            }
            ftpClient.setFileType(FTP.IMAGE_FILE_TYPE);
            ftpClient.enterLocalPassiveMode();
            return ftpClient;
        } catch (Exception exc) {
            System.err.println("Could not connect to ftp server:" + exc);
            return null;
        }
    }
public static byte[] ComputeForBinary(String ThisString) throws Exception {
        byte[] Result;
        MessageDigest MD5Hasher;
        MD5Hasher = MessageDigest.getInstance("MD5");
        MD5Hasher.update(ThisString.getBytes("iso-8859-1"));
        Result = MD5Hasher.digest();
        return Result;
    }
public static byte[] ComputeForText(String ThisString) throws Exception {
        byte[] Result;
        MessageDigest MD5Hasher;
        MD5Hasher = MessageDigest.getInstance("MD5");
        MD5Hasher.update(ThisString.replaceAll("\r", "").getBytes("iso-8859-1"));
        Result = MD5Hasher.digest();
        return Result;
    }
public void put(String path, File fileToPut) throws IOException {
        FTPClient ftp = new FTPClient();
        try {
            int reply;
            ftp.connect(this.endpointURL, this.endpointPort);
            log.debug("Ftp put reply: " + ftp.getReplyString());
            reply = ftp.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                ftp.disconnect();
                throw new IOException("Ftp put server refused connection.");
            }
            if (!ftp.login("anonymous", "")) {
                ftp.logout();
                throw new IOException("FTP: server wrong passwd");
            }
            ftp.setFileType(FTP.BINARY_FILE_TYPE);
            ftp.enterLocalPassiveMode();
            InputStream input = new FileInputStream(fileToPut);
            if (ftp.storeFile(path, input) != true) {
                ftp.logout();
                input.close();
                throw new IOException("FTP put exception");
            }
            input.close();
            ftp.logout();
        } catch (Exception e) {
            log.error("Ftp client exception: " + e.getMessage(), e);
            throw new IOException(e.getMessage());
        }
    }