semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void loadXML(URL flux, int status, File file) {
        try {
            SAXBuilder sbx = new SAXBuilder();
            try {
                if (file.exists()) {
                    file.delete();
                }
                if (!file.exists()) {
                    URLConnection conn = flux.openConnection();
                    conn.setConnectTimeout(5000);
                    conn.setReadTimeout(10000);
                    InputStream is = conn.getInputStream();
                    OutputStream out = new FileOutputStream(file);
                    byte buf[] = new byte[1024];
                    int len;
                    while ((len = is.read(buf)) > 0) out.write(buf, 0, len);
                    out.close();
                    is.close();
                }
            } catch (Exception e) {
                Log.e(Constants.PROJECT_TAG, "Exeption retrieving XML", e);
            }
            try {
                document = sbx.build(new FileInputStream(file));
            } catch (Exception e) {
                Log.e(Constants.PROJECT_TAG, "xml error ", e);
            }
        } catch (Exception e) {
            Log.e(Constants.PROJECT_TAG, "TsukiQueryError", e);
        }
        if (document != null) {
            root = document.getRootElement();
            PopulateDatabase(root, status);
        }
    }
@Test
    public void lookingUpResources() throws IOException {
        StickyEmbedder b = new StickyEmbedder("--debug", "--trace") {

            @Override
            protected File deriveApplicationFile() {
                return new File("src/test/samples/sticky-deployer-sample-2jar-1.2-sample.jar");
            }
        };
        b.initialise();
        assertThat(b.getLibraries()).hasSize(2);
        assertThat(b.getLibraries().iterator().next().getClasses()).hasSize(1);
        assertThat(b.getLibraries().iterator().next().getResources()).hasSize(8);
        URL url = b.getClassLoader().findResource("net/stickycode/deploy/sample/babysteps/run.properties");
        assertThat(url).isNotNull();
        InputStream i = url.openStream();
        assertThat(i).isNotNull();
        assertThat(new BufferedReader(new InputStreamReader(i)).readLine()).isEqualTo("run=running is step 3");
        Enumeration<URL> e = b.getClassLoader().findResources("net/stickycode/deploy/sample/babysteps/run.properties");
        assertThat(e.hasMoreElements()).isTrue();
        assertThat(e.nextElement()).isNotNull();
        assertThat(e.hasMoreElements()).isFalse();
        Enumeration<URL> manifests = b.getClassLoader().findResources("net/stickycode/deploy/sample/duplicate.properties");
        assertThat(manifests.hasMoreElements()).isTrue();
        assertThat(manifests.nextElement()).isNotNull();
        assertThat(manifests.hasMoreElements()).isTrue();
        assertThat(manifests.nextElement()).isNotNull();
        assertThat(manifests.hasMoreElements()).isFalse();
    }
private void downloadFtp(File file, URL jurl) throws SocketException, IOException {
        System.out.println("downloadFtp(" + file + ", " + jurl + ")");
        FTPClient client = new FTPClient();
        client.addProtocolCommandListener(new ProtocolCommandListener() {

            public void protocolCommandSent(ProtocolCommandEvent event) {
                System.out.println("downloadFtp: " + event.getMessage());
            }

            public void protocolReplyReceived(ProtocolCommandEvent event) {
                System.out.println("downloadFtp: " + event.getMessage());
            }
        });
        try {
            client.connect(jurl.getHost(), -1 == jurl.getPort() ? FTP.DEFAULT_PORT : jurl.getPort());
            int reply = client.getReplyCode();
            if (!FTPReply.isPositiveCompletion(reply)) {
                client.disconnect();
                throw new IOException("FTP server refused connection.");
            }
            if (!client.login("anonymous", "anonymous")) {
                client.logout();
                throw new IOException("Authentication failure.");
            }
            client.setFileType(FTP.BINARY_FILE_TYPE);
            client.enterLocalPassiveMode();
            FileOutputStream out = new FileOutputStream(file);
            boolean ok = client.retrieveFile(jurl.getPath(), out);
            out.close();
            client.logout();
            if (!ok) {
                throw new IOException("File transfer failure.");
            }
        } catch (IOException e) {
            throw e;
        } finally {
            if (client.isConnected()) {
                try {
                    client.disconnect();
                } catch (IOException e) {
                }
            }
        }
    }
private void loadMap() {
        final String wordList = "vietwordlist.txt";
        try {
            File dataFile = new File(supportDir, wordList);
            if (!dataFile.exists()) {
                final ReadableByteChannel input = Channels.newChannel(ClassLoader.getSystemResourceAsStream("dict/" + dataFile.getName()));
                final FileChannel output = new FileOutputStream(dataFile).getChannel();
                output.transferFrom(input, 0, 1000000L);
                input.close();
                output.close();
            }
            long fileLastModified = dataFile.lastModified();
            if (map == null) {
                map = new HashMap<String, String>();
            } else {
                if (fileLastModified <= mapLastModified) {
                    return;
                }
                map.clear();
            }
            mapLastModified = fileLastModified;
            BufferedReader bs = new BufferedReader(new InputStreamReader(new FileInputStream(dataFile), "UTF-8"));
            String accented;
            while ((accented = bs.readLine()) != null) {
                String plain = VietUtilities.stripDiacritics(accented);
                map.put(plain.toLowerCase(), accented);
            }
            bs.close();
        } catch (IOException e) {
            map = null;
            e.printStackTrace();
            JOptionPane.showMessageDialog(this, myResources.getString("Cannot_find_\"") + wordList + myResources.getString("\"_in\n") + supportDir.toString(), VietPad.APP_NAME, JOptionPane.ERROR_MESSAGE);
        }
    }
private DictionaryListParser downloadList(final String url) throws IOException, JSONException {
        final HttpClient client = new DefaultHttpClient();
        final HttpGet httpGet = new HttpGet(url);
        final HttpResponse response = client.execute(httpGet);
        final HttpEntity entity = response.getEntity();
        if (entity == null) {
            throw new IOException("HttpResponse.getEntity() IS NULL");
        }
        final boolean isValidType = entity.getContentType().getValue().startsWith(RESPONSE_CONTENT_TYPE);
        if (!isValidType) {
            final String message = "CONTENT_TYPE IS '" + entity.getContentType().getValue() + "'";
            throw new IOException(message);
        }
        final BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent(), RESPONSE_ENCODING));
        final StringBuilder stringResult = new StringBuilder();
        try {
            for (String line = reader.readLine(); line != null; line = reader.readLine()) {
                stringResult.append(line);
            }
        } finally {
            reader.close();
        }
        return new DictionaryListParser(stringResult);
    }
private InputStream getInputStream() throws URISyntaxException, MalformedURLException, IOException {
        InputStream inStream = null;
        try {
            URL url = new URI(wsdlFile).toURL();
            URLConnection connection = url.openConnection();
            connection.connect();
            inStream = connection.getInputStream();
        } catch (IllegalArgumentException ex) {
            inStream = new FileInputStream(wsdlFile);
        }
        return inStream;
    }
public static void main(String[] args) throws Exception {
        if (args.length != 2) {
            System.out.println("usage: PutFromFile [properties file] [file with pmpxml]");
            throw new IllegalArgumentException("Wrong number of arguments");
        }
        Reader is = new FileReader(args[1]);
        char[] b = new char[1024];
        StringBuffer sb = new StringBuffer();
        int n;
        while ((n = is.read(b)) > 0) {
            sb.append(b, 0, n);
        }
        String test = sb.toString();
        System.out.println(test);
        String strurl = args[0];
        String data = "verb=PutRecord&xml=" + URLEncoder.encode(test, "UTF-8");
        URL url = new URL(strurl);
        URLConnection conn = url.openConnection();
        conn.setDoOutput(true);
        OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
        wr.write(data);
        wr.flush();
        BufferedReader rd = new BufferedReader(new InputStreamReader(conn.getInputStream()));
        String line;
        while ((line = rd.readLine()) != null) {
            System.out.println(line);
        }
        wr.close();
        rd.close();
    }
public static byte[] getBytesFromURL(URL url) throws IOException {
        byte[] b;
        URLConnection con = url.openConnection();
        int size = con.getContentLength();
        InputStream s = con.getInputStream();
        try {
            if (size <= 0) b = IOUtil.getBytesFromStream(s); else {
                b = new byte[size];
                int len = 0;
                do {
                    int n = s.read(b, len, size - len);
                    if (n < 0) throw new IOException("the stream was closed: " + url.toString());
                    len += n;
                } while (len < size);
            }
        } finally {
            s.close();
        }
        return b;
    }
public static void processRequest(byte[] b) throws Exception {
        URL url = new URL("http://localhost:8080/instantsoap-ws-echotest-1.0/services/instantsoap/applications");
        URLConnection connection = url.openConnection();
        HttpURLConnection httpConn = (HttpURLConnection) connection;
        httpConn.setRequestProperty("Content-Length", String.valueOf(b.length));
        httpConn.setRequestProperty("Content-Type", "text/xml; charset=utf-8");
        httpConn.setRequestProperty("SOAPAction", "");
        httpConn.setRequestMethod("POST");
        httpConn.setDoOutput(true);
        httpConn.setDoInput(true);
        OutputStream out = httpConn.getOutputStream();
        out.write(b);
        out.close();
        BufferedReader in = new BufferedReader(new InputStreamReader(httpConn.getInputStream()));
        String inputLine;
        while ((inputLine = in.readLine()) != null) System.out.println(inputLine);
        in.close();
    }
private void copy(File from, File to) {
        if (from.isDirectory()) {
            File[] files = from.listFiles();
            for (int i = 0; i < files.length; i++) {
                if (files[i].isDirectory()) {
                    File newTo = new File(to.getPath() + File.separator + files[i].getName());
                    newTo.mkdirs();
                    copy(files[i], newTo);
                } else {
                    copy(files[i], to);
                }
            }
        } else {
            try {
                to = new File(to.getPath() + File.separator + from.getName());
                to.createNewFile();
                FileChannel src = new FileInputStream(from).getChannel();
                FileChannel dest = new FileOutputStream(to).getChannel();
                dest.transferFrom(src, 0, src.size());
                dest.close();
                src.close();
            } catch (FileNotFoundException e) {
                errorLog(e.toString());
                e.printStackTrace();
            } catch (IOException e) {
                errorLog(e.toString());
                e.printStackTrace();
            }
        }
    }
private JButton getButtonImagen() {
        if (buttonImagen == null) {
            buttonImagen = new JButton();
            buttonImagen.setText(Messages.getString("gui.AdministracionResorces.6"));
            buttonImagen.setIcon(new ImageIcon(getClass().getResource("/es/unizar/cps/tecnoDiscap/data/icons/view_sidetree.png")));
            buttonImagen.addActionListener(new java.awt.event.ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent e) {
                    JFileChooser fc = new JFileChooser();
                    fc.addChoosableFileFilter(new ImageFilter());
                    fc.setAccessory(new ImagePreview(fc));
                    int returnVal = fc.showDialog(AdministracionResorces.this, Messages.getString("gui.AdministracionResorces.8"));
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        File file = fc.getSelectedFile();
                        String rutaGlobal = System.getProperty("user.dir") + "/" + rutaDatos + "imagenes/" + file.getName();
                        String rutaRelativa = rutaDatos + "imagenes/" + file.getName();
                        try {
                            FileInputStream fis = new FileInputStream(file);
                            FileOutputStream fos = new FileOutputStream(rutaGlobal, true);
                            FileChannel canalFuente = fis.getChannel();
                            FileChannel canalDestino = fos.getChannel();
                            canalFuente.transferTo(0, canalFuente.size(), canalDestino);
                            fis.close();
                            fos.close();
                            imagen.setImagenURL(rutaRelativa);
                            gui.getEntrenamientoIzquierdaLabel().setIcon(gui.getProcesadorDatos().escalaImageIcon(((Imagen) gui.getComboBoxImagenesIzquierda().getSelectedItem()).getImagenURL()));
                            gui.getEntrenamientoDerechaLabel().setIcon(gui.getProcesadorDatos().escalaImageIcon(((Imagen) gui.getComboBoxImagenesDerecha().getSelectedItem()).getImagenURL()));
                            buttonImagen.setIcon(new ImageIcon(getClass().getResource("/es/unizar/cps/tecnoDiscap/data/icons/view_sidetreeOK.png")));
                            labelImagenPreview.setIcon(gui.getProcesadorDatos().escalaImageIcon(imagen.getImagenURL()));
                        } catch (IOException ex) {
                            ex.printStackTrace();
                        }
                    } else {
                    }
                }
            });
        }
        return buttonImagen;
    }
public void actionPerformed(java.awt.event.ActionEvent e) {
                    JFileChooser fc = new JFileChooser();
                    fc.addChoosableFileFilter(new ImageFilter());
                    fc.setAccessory(new ImagePreview(fc));
                    int returnVal = fc.showDialog(AdministracionResorces.this, Messages.getString("gui.AdministracionResorces.8"));
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        File file = fc.getSelectedFile();
                        String rutaGlobal = System.getProperty("user.dir") + "/" + rutaDatos + "imagenes/" + file.getName();
                        String rutaRelativa = rutaDatos + "imagenes/" + file.getName();
                        try {
                            FileInputStream fis = new FileInputStream(file);
                            FileOutputStream fos = new FileOutputStream(rutaGlobal, true);
                            FileChannel canalFuente = fis.getChannel();
                            FileChannel canalDestino = fos.getChannel();
                            canalFuente.transferTo(0, canalFuente.size(), canalDestino);
                            fis.close();
                            fos.close();
                            imagen.setImagenURL(rutaRelativa);
                            gui.getEntrenamientoIzquierdaLabel().setIcon(gui.getProcesadorDatos().escalaImageIcon(((Imagen) gui.getComboBoxImagenesIzquierda().getSelectedItem()).getImagenURL()));
                            gui.getEntrenamientoDerechaLabel().setIcon(gui.getProcesadorDatos().escalaImageIcon(((Imagen) gui.getComboBoxImagenesDerecha().getSelectedItem()).getImagenURL()));
                            buttonImagen.setIcon(new ImageIcon(getClass().getResource("/es/unizar/cps/tecnoDiscap/data/icons/view_sidetreeOK.png")));
                            labelImagenPreview.setIcon(gui.getProcesadorDatos().escalaImageIcon(imagen.getImagenURL()));
                        } catch (IOException ex) {
                            ex.printStackTrace();
                        }
                    } else {
                    }
                }
private JButton getButtonSonido() {
        if (buttonSonido == null) {
            buttonSonido = new JButton();
            buttonSonido.setText(Messages.getString("gui.AdministracionResorces.15"));
            buttonSonido.setIcon(new ImageIcon(getClass().getResource("/es/unizar/cps/tecnoDiscap/data/icons/view_sidetree.png")));
            buttonSonido.addActionListener(new java.awt.event.ActionListener() {

                public void actionPerformed(java.awt.event.ActionEvent e) {
                    JFileChooser fc = new JFileChooser();
                    fc.addChoosableFileFilter(new SoundFilter());
                    int returnVal = fc.showDialog(AdministracionResorces.this, Messages.getString("gui.AdministracionResorces.17"));
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        File file = fc.getSelectedFile();
                        String rutaGlobal = System.getProperty("user.dir") + "/" + rutaDatos + "sonidos/" + file.getName();
                        String rutaRelativa = rutaDatos + "sonidos/" + file.getName();
                        try {
                            FileInputStream fis = new FileInputStream(file);
                            FileOutputStream fos = new FileOutputStream(rutaGlobal, true);
                            FileChannel canalFuente = fis.getChannel();
                            FileChannel canalDestino = fos.getChannel();
                            canalFuente.transferTo(0, canalFuente.size(), canalDestino);
                            fis.close();
                            fos.close();
                            imagen.setSonidoURL(rutaRelativa);
                            System.out.println(rutaGlobal + " " + rutaRelativa);
                            buttonSonido.setIcon(new ImageIcon(getClass().getResource("/es/unizar/cps/tecnoDiscap/data/icons/view_sidetreeOK.png")));
                            gui.getAudio().reproduceAudio(imagen);
                        } catch (IOException ex) {
                            ex.printStackTrace();
                        }
                    } else {
                    }
                }
            });
        }
        return buttonSonido;
    }
public void actionPerformed(java.awt.event.ActionEvent e) {
                    JFileChooser fc = new JFileChooser();
                    fc.addChoosableFileFilter(new SoundFilter());
                    int returnVal = fc.showDialog(AdministracionResorces.this, Messages.getString("gui.AdministracionResorces.17"));
                    if (returnVal == JFileChooser.APPROVE_OPTION) {
                        File file = fc.getSelectedFile();
                        String rutaGlobal = System.getProperty("user.dir") + "/" + rutaDatos + "sonidos/" + file.getName();
                        String rutaRelativa = rutaDatos + "sonidos/" + file.getName();
                        try {
                            FileInputStream fis = new FileInputStream(file);
                            FileOutputStream fos = new FileOutputStream(rutaGlobal, true);
                            FileChannel canalFuente = fis.getChannel();
                            FileChannel canalDestino = fos.getChannel();
                            canalFuente.transferTo(0, canalFuente.size(), canalDestino);
                            fis.close();
                            fos.close();
                            imagen.setSonidoURL(rutaRelativa);
                            System.out.println(rutaGlobal + " " + rutaRelativa);
                            buttonSonido.setIcon(new ImageIcon(getClass().getResource("/es/unizar/cps/tecnoDiscap/data/icons/view_sidetreeOK.png")));
                            gui.getAudio().reproduceAudio(imagen);
                        } catch (IOException ex) {
                            ex.printStackTrace();
                        }
                    } else {
                    }
                }
public static List<String> list() throws IOException {
        List<String> providers = new ArrayList<String>();
        Enumeration<URL> urls = ClassLoader.getSystemResources("sentrick.classifiers");
        while (urls.hasMoreElements()) {
            URL url = urls.nextElement();
            String provider = null;
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            while ((provider = in.readLine()) != null) {
                provider = provider.trim();
                if (provider.length() > 0) providers.add(provider);
            }
            in.close();
        }
        return providers;
    }
public static String httpUrlConnection_post(String targetURL, String urlParameters) {
        System.out.println("httpUrlConnection_post");
        URL url;
        HttpURLConnection connection = null;
        try {
            url = new URL(targetURL);
            connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            connection.setRequestProperty("Content-Length", "" + Integer.toString(urlParameters.getBytes().length));
            connection.setRequestProperty("Content-Language", "en-US");
            connection.setUseCaches(false);
            connection.setConnectTimeout(5000);
            connection.setReadTimeout(5000);
            connection.setDoInput(true);
            connection.setDoOutput(true);
            DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
            wr.writeBytes(urlParameters);
            wr.flush();
            wr.close();
            InputStream is = connection.getInputStream();
            BufferedReader rd = new BufferedReader(new InputStreamReader(is));
            String line;
            StringBuilder response = new StringBuilder();
            while ((line = rd.readLine()) != null) {
                response.append(line);
                response.append('\r');
            }
            rd.close();
            return response.toString();
        } catch (Exception e) {
            System.out.print(e);
            return null;
        } finally {
            if (connection != null) {
                connection.disconnect();
            }
        }
    }
private static byte[] sha2(String... data) {
        byte[] digest = new byte[32];
        StringBuilder buffer = new StringBuilder();
        for (String s : data) {
            buffer.append(s);
        }
        MessageDigest sha256 = null;
        try {
            sha256 = MessageDigest.getInstance("SHA-256");
        } catch (NoSuchAlgorithmException ex) {
            assert false;
        }
        sha256.update(buffer.toString().getBytes());
        try {
            sha256.digest(digest, 0, digest.length);
        } catch (DigestException ex) {
            assert false;
        }
        return digest;
    }
public byte[] loadClassFirst(final String className) {
        if (className.equals("com.sun.sgs.impl.kernel.KernelContext")) {
            final URL url = Thread.currentThread().getContextClassLoader().getResource("com/sun/sgs/impl/kernel/KernelContext.0.9.6.class.bin");
            if (url != null) {
                try {
                    return StreamUtil.read(url.openStream());
                } catch (IOException e) {
                }
            }
            throw new IllegalStateException("Unable to load KernelContext.0.9.6.class.bin");
        }
        return null;
    }