semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
@Test
    public void testWriteAndReadBiggerUnbuffered() throws Exception {
        JCFSFileServer server = new JCFSFileServer(defaultTcpPort, defaultTcpAddress, defaultUdpPort, defaultUdpAddress, dir, 0, 0);
        JCFS.configureDiscovery(defaultUdpAddress, defaultUdpPort);
        try {
            server.start();
            RFile file = new RFile("testreadwriteb.txt");
            RFileOutputStream out = new RFileOutputStream(file);
            String body = "";
            int size = 50 * 1024;
            for (int i = 0; i < size; i++) {
                body = body + "a";
            }
            out.write(body.getBytes("utf-8"));
            out.close();
            File expected = new File(dir, "testreadwriteb.txt");
            assertTrue(expected.isFile());
            assertEquals(body.length(), expected.length());
            RFileInputStream in = new RFileInputStream(file);
            ByteArrayOutputStream tmp = new ByteArrayOutputStream();
            int b = in.read();
            while (b != -1) {
                tmp.write(b);
                b = in.read();
            }
            byte[] buffer = tmp.toByteArray();
            in.close();
            assertEquals(body.length(), buffer.length);
            String resultRead = new String(buffer, "utf-8");
            assertEquals(body, resultRead);
        } finally {
            server.stop();
        }
    }
public static byte[] sendRequestV2(String url, String content, Map<String, String> headers, String method, String contenttype) {
        byte[] result = null;
        try {
            HttpURLConnection httpConn = (HttpURLConnection) new URL(url).openConnection();
            httpConn.setUseCaches(false);
            httpConn.setInstanceFollowRedirects(true);
            httpConn.setRequestMethod(method);
            httpConn.setRequestProperty("Content-Type", contenttype);
            httpConn.setRequestProperty("Accept-Encoding", "gzip");
            if (headers != null && headers.size() > 0) {
                Iterator<String> keys = headers.keySet().iterator();
                while (keys.hasNext()) {
                    String key = keys.next();
                    httpConn.setRequestProperty(key, headers.get(key));
                }
            }
            httpConn.setDoOutput(true);
            if (content != null) httpConn.getOutputStream().write(content.getBytes("UTF-8"));
            System.setProperty("http.strictPostRedirect", "true");
            httpConn.connect();
            ByteArrayOutputStream bout = new ByteArrayOutputStream();
            try {
                InputStream in = httpConn.getInputStream();
                byte[] buf = new byte[500];
                int count = 0;
                while ((count = in.read(buf)) > 0) {
                    bout.write(buf, 0, count);
                }
                result = bout.toByteArray();
            } catch (Exception ex) {
                ex.printStackTrace();
            } finally {
                if (bout != null) bout.close();
            }
            System.clearProperty("http.strictPostRedirect");
        } catch (Exception e) {
            logger.error(e, e);
        }
        return result;
    }
private void checkForLatestVersion() {
        log(Color.BLUE, "Checking for latest version.");
        try {
            double LatestVersion = 0.0;
            URL url = new URL("http://www.powerbot.org/vb/showthread.php?t=723144");
            URLConnection urlc = url.openConnection();
            BufferedReader bf = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
            String CurrentLine;
            while ((CurrentLine = bf.readLine()) != null) {
                if (CurrentLine.contains("<pre class=\"bbcode_code\"style=\"height:48px;\"><i>Current version")) {
                    for (String s : CurrentLine.split(" ")) {
                        try {
                            LatestVersion = Double.parseDouble(s);
                        } catch (NumberFormatException nfe) {
                        }
                    }
                }
            }
            double CurrentVersion = getClass().getAnnotation(ScriptManifest.class).version();
            String Message = LatestVersion < CurrentVersion ? ", you should update to the latest version!" : ", you have the latest version of this script.";
            log(LatestVersion < CurrentVersion ? Color.RED : Color.BLUE, "Latest version available : " + LatestVersion + Message);
        } catch (IOException ioe) {
            log(Color.RED, "Couldn't retreive latest version due to a connection issue!");
        } catch (NumberFormatException nfe) {
            log(Color.RED, "Couldn't reveice latest version; no version were available on PowerBot website!.");
        } catch (Exception e) {
            log(Color.RED, "Couldn't retreive latest version due to an unknown reason!");
        }
    }
@Override
    protected String doInBackground(String... params) {
        try {
            URL url = new URL("http://www.foamsnet.com/smsapi/send.php?username=" + username + "&password=" + password + "&to=" + to + "&msg=" + URLEncoder.encode(msg));
            URLConnection urlc = url.openConnection();
            BufferedReader sin = new BufferedReader(new InputStreamReader(urlc.getInputStream()));
            String inputLine = sin.readLine();
            inputLine = inputLine == null ? "null" : inputLine;
            sin.close();
            output = inputLine;
            if (logsent) {
                ContentResolver contentResolver = cr;
                ContentValues values = new ContentValues();
                values.put("address", "+91" + inputLine.split(" ")[3]);
                values.put("body", msg);
                contentResolver.insert(Uri.parse("content://sms/sent"), values);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
private static void addFileToZip(String path, String srcFile, ZipOutputStream zip, String prefix, String suffix) throws Exception {
        File folder = new File(srcFile);
        if (folder.isDirectory()) {
            addFolderToZip(path, srcFile, zip, prefix, suffix);
        } else {
            if (isFileNameMatch(folder.getName(), prefix, suffix)) {
                FileInputStream fis = new FileInputStream(srcFile);
                zip.putNextEntry(new ZipEntry(path + "/" + folder.getName()));
                IOUtils.copy(fis, zip);
                fis.close();
            }
        }
    }
public static void extractZipPackage(String fileName, String destinationFolder) throws Exception {
        if (NullStatus.isNull(destinationFolder)) {
            destinationFolder = "";
        }
        new File(destinationFolder).mkdirs();
        File inputFile = new File(fileName);
        ZipFile zipFile = new ZipFile(inputFile);
        Enumeration<? extends ZipEntry> oEnum = zipFile.entries();
        while (oEnum.hasMoreElements()) {
            ZipEntry zipEntry = oEnum.nextElement();
            File file = new File(destinationFolder + "/" + zipEntry.getName());
            if (zipEntry.isDirectory()) {
                file.mkdirs();
            } else {
                String destinationFolderName = destinationFolder + "/" + zipEntry.getName();
                destinationFolderName = destinationFolderName.substring(0, destinationFolderName.lastIndexOf("/"));
                new File(destinationFolderName).mkdirs();
                FileOutputStream fos = new FileOutputStream(file);
                IOUtils.copy(zipFile.getInputStream(zipEntry), fos);
                fos.close();
            }
        }
    }
public void unpack(File destDirectory, boolean delete) {
        if (delete) delete(destDirectory);
        if (destDirectory.exists()) throw new ContentPackageException("Destination directory already exists.");
        this.destDirectory = destDirectory;
        this.manifestFile = new File(destDirectory, MANIFEST_FILE_NAME);
        try {
            if (zipInputStream == null) zipInputStream = new ZipInputStream(new FileInputStream(zipFile));
            ZipEntry zipEntry;
            while ((zipEntry = zipInputStream.getNextEntry()) != null) {
                File destFile = new File(destDirectory, zipEntry.getName());
                destFile.getParentFile().mkdirs();
                if (!zipEntry.isDirectory()) {
                    BufferedOutputStream output = new BufferedOutputStream(new FileOutputStream(destFile), BUFFER_SIZE);
                    byte[] buffer = new byte[BUFFER_SIZE];
                    int length;
                    while ((length = zipInputStream.read(buffer, 0, BUFFER_SIZE)) != -1) output.write(buffer, 0, length);
                    output.close();
                    zipInputStream.closeEntry();
                }
            }
            zipInputStream.close();
        } catch (IOException ex) {
            throw new ContentPackageException(ex);
        }
    }
public InputStream getResourceStream(String resource) {
        try {
            URL url = getClass().getResource(resource);
            System.out.println("URL: " + url);
            System.out.println("Read ROM " + resource);
            if (url == null) url = new URL(codebase + resource);
            return url.openConnection().getInputStream();
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
public void submitReport() {
        String subject = m_Subject.getText();
        String description = m_Description.getText();
        String email = m_Email.getText();
        if (subject.length() == 0) {
            Util.flashComponent(m_Subject, Color.RED);
            return;
        }
        if (description.length() == 0) {
            Util.flashComponent(m_Description, Color.RED);
            return;
        }
        DynamicLocalisation loc = m_MainFrame.getLocalisation();
        if (email.length() == 0 || email.indexOf("@") == -1 || email.indexOf(".") == -1 || email.startsWith("@")) {
            email = "anonymous@blaat.com";
        }
        try {
            String data = URLEncoder.encode("mode", "UTF-8") + "=" + URLEncoder.encode("manual", "UTF-8");
            data += "&" + URLEncoder.encode("from", "UTF-8") + "=" + URLEncoder.encode(email, "UTF-8");
            data += "&" + URLEncoder.encode("subject", "UTF-8") + "=" + URLEncoder.encode(subject, "UTF-8");
            data += "&" + URLEncoder.encode("body", "UTF-8") + "=" + URLEncoder.encode(description, "UTF-8");
            data += "&" + URLEncoder.encode("jvm", "UTF-8") + "=" + URLEncoder.encode(System.getProperty("java.version"), "UTF-8");
            data += "&" + URLEncoder.encode("ocdsver", "UTF-8") + "=" + URLEncoder.encode(Constants.OPENCDS_VERSION, "UTF-8");
            data += "&" + URLEncoder.encode("os", "UTF-8") + "=" + URLEncoder.encode(Constants.OS_NAME + " " + System.getProperty("os.version") + " " + System.getProperty("os.arch"), "UTF-8");
            URL url = new URL(Constants.BUGREPORT_SCRIPT);
            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();
            JOptionPane.showMessageDialog(this, loc.getMessage("ReportBug.SentMessage"));
        } catch (Exception e) {
            Logger.getInstance().logException(e);
        }
        dispose();
    }
public void sendMessage(Message m) throws IOException {
        URL url = new URL(strURL);
        urlcon = (HttpURLConnection) url.openConnection();
        urlcon.setUseCaches(false);
        urlcon.setDefaultUseCaches(false);
        urlcon.setDoOutput(true);
        urlcon.setDoInput(true);
        urlcon.setRequestProperty("Content-type", "application/octet-stream");
        urlcon.setAllowUserInteraction(false);
        HttpURLConnection.setDefaultAllowUserInteraction(false);
        urlcon.setRequestMethod("POST");
        ObjectOutputStream oos = new ObjectOutputStream(urlcon.getOutputStream());
        oos.writeObject(m);
        oos.flush();
        oos.close();
    }
void IconmenuItem5_actionPerformed(ActionEvent e) {
        JFileChooser jFileChooser1 = new JFileChooser();
        String separator = "";
        if (getPath() != null && !getPath().equals("")) {
            jFileChooser1.setCurrentDirectory(new File(getPath()));
            jFileChooser1.setSelectedFile(new File(getPath()));
        }
        if (JFileChooser.APPROVE_OPTION == jFileChooser1.showOpenDialog(this.getFatherFrame())) {
            setPath(jFileChooser1.getSelectedFile().getPath());
            separator = jFileChooser1.getSelectedFile().separator;
            File dirImg = new File("." + separator + "images");
            if (!dirImg.exists()) {
                dirImg.mkdir();
            }
            int index = getPath().lastIndexOf(separator);
            String imgName = getPath().substring(index);
            String newPath = dirImg + imgName;
            try {
                File inputFile = new File(getPath());
                File outputFile = new File(newPath);
                if (!inputFile.getCanonicalPath().equals(outputFile.getCanonicalPath())) {
                    FileInputStream in = new FileInputStream(inputFile);
                    FileOutputStream out = new FileOutputStream(outputFile);
                    int c;
                    while ((c = in.read()) != -1) out.write(c);
                    in.close();
                    out.close();
                }
            } catch (Exception ex) {
                ex.printStackTrace();
                LogHandler.log(ex.getMessage(), Level.INFO, "LOG_MSG", isLoggingEnabled());
                JOptionPane.showMessageDialog(null, ex.getMessage().substring(0, Math.min(ex.getMessage().length(), getFatherPanel().MAX_DIALOG_MSG_SZ)) + "-" + getClass(), "", JOptionPane.ERROR_MESSAGE);
            }
            setPath(newPath);
            if (getDefaultPath() == null || getDefaultPath().equals("")) {
                String msgString = "E' stata selezionata un'immagine da associare all'IconShape, ma non e' " + "stata selezionata ancora nessun'immagine di default. Imposto quella scelta anche come " + "immagine di default?";
                if (JOptionPane.showConfirmDialog(null, msgString.substring(0, Math.min(msgString.length(), getFatherPanel().MAX_DIALOG_MSG_SZ)), "choose one", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION) {
                    setDefaultPath(newPath);
                    createDefaultImage();
                }
            }
            createImage();
        }
    }
void IconmenuItem6_actionPerformed(ActionEvent e) {
        JFileChooser jFileChooser1 = new JFileChooser();
        String separator = "";
        if (JFileChooser.APPROVE_OPTION == jFileChooser1.showOpenDialog(this.getFatherFrame())) {
            setDefaultPath(jFileChooser1.getSelectedFile().getPath());
            separator = jFileChooser1.getSelectedFile().separator;
            File dirImg = new File("." + separator + "images");
            if (!dirImg.exists()) {
                dirImg.mkdir();
            }
            int index = getDefaultPath().lastIndexOf(separator);
            String imgName = getDefaultPath().substring(index);
            String newPath = dirImg + imgName;
            try {
                File inputFile = new File(getDefaultPath());
                File outputFile = new File(newPath);
                FileInputStream in = new FileInputStream(inputFile);
                FileOutputStream out = new FileOutputStream(outputFile);
                int c;
                while ((c = in.read()) != -1) out.write(c);
                in.close();
                out.close();
            } catch (Exception ex) {
                ex.printStackTrace();
                LogHandler.log(ex.getMessage(), Level.INFO, "LOG_MSG", isLoggingEnabled());
                JOptionPane.showMessageDialog(null, ex.getMessage().substring(0, Math.min(ex.getMessage().length(), getFatherPanel().MAX_DIALOG_MSG_SZ)) + "-" + getClass(), "", JOptionPane.ERROR_MESSAGE);
            }
            setDefaultPath(newPath);
            createDefaultImage();
        }
    }
public static void bubbleSort(int[] a) {
        if (a == null) {
            throw new IllegalArgumentException("Null-pointed array");
        }
        int right = a.length - 1;
        int k = 0;
        while (right > 0) {
            k = 0;
            for (int i = 0; i <= right - 1; i++) {
                if (a[i] > a[i + 1]) {
                    k = i;
                    int temp = a[i];
                    a[i] = a[i + 1];
                    a[i + 1] = temp;
                }
            }
            right = k;
        }
    }
public static void shakeSort(int[] a) {
        if (a == null) {
            throw new IllegalArgumentException("Null-pointed array");
        }
        int k = 0;
        int left = 0;
        int right = a.length - 1;
        while (right - left > 0) {
            k = 0;
            for (int i = 0; i <= right - 1; i++) {
                if (a[i] > a[i + 1]) {
                    k = i;
                    int temp = a[i];
                    a[i] = a[i + 1];
                    a[i + 1] = temp;
                }
            }
            right = k;
            k = a.length - 1;
            for (int i = left; i <= right - 1; i++) {
                if (a[i] > a[i + 1]) {
                    k = i;
                    int temp = a[i];
                    a[i] = a[i + 1];
                    a[i + 1] = temp;
                }
            }
            left = k;
        }
    }
protected String encrypt(final String data, final String key) throws CryptographicFailureException {
        Validate.notNull(data, "Provided data cannot be null.");
        Validate.notNull(key, "Provided key name cannot be null.");
        final PublicKey pk = getPublicKey(key);
        if (pk == null) {
            throw new CryptographicFailureException("PublicKeyNotFound", String.format("Cannot find public key '%s'", key));
        }
        try {
            final Cipher cipher = Cipher.getInstance(pk.getAlgorithm());
            cipher.init(Cipher.ENCRYPT_MODE, pk);
            final ByteArrayInputStream bin = new ByteArrayInputStream(data.getBytes());
            final CipherInputStream cin = new CipherInputStream(bin, cipher);
            final ByteArrayOutputStream bout = new ByteArrayOutputStream();
            IOUtils.copy(cin, bout);
            return new String(Base64.encodeBase64(bout.toByteArray()));
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException(String.format("Cannot find instance of algorithm '%s'", pk.getAlgorithm()), e);
        } catch (NoSuchPaddingException e) {
            throw new IllegalStateException(String.format("Cannot build instance of algorithm '%s'", pk.getAlgorithm()), e);
        } catch (InvalidKeyException e) {
            throw new IllegalStateException(String.format("Cannot build instance of algorithm '%s'", pk.getAlgorithm()), e);
        } catch (IOException e) {
            throw new IllegalStateException("Cannot build in-memory cipher copy", e);
        }
    }
protected String decrypt(final String data, final String key) throws CryptographicFailureException {
        Validate.notNull(data, "Provided data cannot be null.");
        Validate.notNull(key, "Provided key name cannot be null.");
        final PrivateKey pk = getPrivateKey(key);
        if (pk == null) {
            throw new CryptographicFailureException("PrivateKeyNotFound", String.format("Cannot find private key '%s'", key));
        }
        try {
            final Cipher cipher = Cipher.getInstance(pk.getAlgorithm());
            cipher.init(Cipher.DECRYPT_MODE, pk);
            final ByteArrayInputStream bin = new ByteArrayInputStream(Base64.decodeBase64(data.getBytes()));
            final CipherInputStream cin = new CipherInputStream(bin, cipher);
            final ByteArrayOutputStream bout = new ByteArrayOutputStream();
            IOUtils.copy(cin, bout);
            return new String(bout.toByteArray());
        } catch (NoSuchAlgorithmException e) {
            throw new IllegalStateException(String.format("Cannot find instance of algorithm '%s'", pk.getAlgorithm()), e);
        } catch (NoSuchPaddingException e) {
            throw new IllegalStateException(String.format("Cannot build instance of algorithm '%s'", pk.getAlgorithm()), e);
        } catch (InvalidKeyException e) {
            throw new IllegalStateException(String.format("Cannot build instance of algorithm '%s'", pk.getAlgorithm()), e);
        } catch (IOException e) {
            throw new IllegalStateException("Cannot build in-memory cipher copy", e);
        }
    }
public GLatLng geoCodeAddress(SearchParms searchParms) throws IOException {
        logger.debug(searchParms.getGeocodeAddress());
        URL url = new URL(geocoder.encode(searchParms.getGeocodeAddress()));
        URLConnection connection = url.openConnection();
        String content = Streams.readString(connection.getInputStream());
        return geocoder.decode(content);
    }