semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public boolean copyFile(File destinationFolder, File fromFile) {
        boolean result = false;
        String toFileName = destinationFolder.getAbsolutePath() + "/" + fromFile.getName();
        File toFile = new File(toFileName);
        FileInputStream from = null;
        FileOutputStream to = null;
        try {
            from = new FileInputStream(fromFile);
            to = new FileOutputStream(toFile);
            byte[] buffer = new byte[4096];
            int bytesRead;
            while ((bytesRead = from.read(buffer)) != -1) to.write(buffer, 0, bytesRead);
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (from != null) {
                try {
                    from.close();
                } catch (IOException e2) {
                    e2.printStackTrace();
                }
                if (to != null) {
                    try {
                        to.close();
                        result = true;
                    } catch (IOException e3) {
                        e3.printStackTrace();
                    }
                }
            }
        }
        return result;
    }
public static Result checkLink(String theUrl) throws MalformedURLException {
        URL url = new URL(theUrl);
        HttpURLConnection urlConnection = null;
        try {
            urlConnection = (HttpURLConnection) url.openConnection();
            urlConnection.setConnectTimeout(5000);
            urlConnection.setRequestMethod("GET");
            urlConnection.connect();
            return new Result(urlConnection.getResponseCode(), false);
        } catch (IOException e) {
            return new Result(0, true);
        } finally {
            if (urlConnection != null) {
                urlConnection.disconnect();
            }
        }
    }
public static void compress(File srcFile, File destFile) throws IOException {
        InputStream input = null;
        OutputStream output = null;
        try {
            input = new BufferedInputStream(new FileInputStream(srcFile));
            output = new GZIPOutputStream(new FileOutputStream(destFile));
            IOUtils.copyLarge(input, output);
        } finally {
            IOUtils.closeQuietly(output);
            IOUtils.closeQuietly(input);
        }
    }
public static void uncompress(File srcFile, File destFile) throws IOException {
        InputStream input = null;
        OutputStream output = null;
        try {
            input = new GZIPInputStream(new FileInputStream(srcFile));
            output = new BufferedOutputStream(new FileOutputStream(destFile));
            IOUtils.copyLarge(input, output);
        } finally {
            IOUtils.closeQuietly(output);
            IOUtils.closeQuietly(input);
        }
    }
@Test
    public void testTrainingDefault() throws IOException {
        File temp = File.createTempFile("fannj_", ".tmp");
        temp.deleteOnExit();
        IOUtils.copy(this.getClass().getResourceAsStream("xor.data"), new FileOutputStream(temp));
        List<Layer> layers = new ArrayList<Layer>();
        layers.add(Layer.create(2));
        layers.add(Layer.create(3, ActivationFunction.FANN_SIGMOID_SYMMETRIC));
        layers.add(Layer.create(1, ActivationFunction.FANN_SIGMOID_SYMMETRIC));
        Fann fann = new Fann(layers);
        Trainer trainer = new Trainer(fann);
        float desiredError = .001f;
        float mse = trainer.train(temp.getPath(), 500000, 1000, desiredError);
        assertTrue("" + mse, mse <= desiredError);
    }
@Test
    public void testTrainingQuickprop() throws IOException {
        File temp = File.createTempFile("fannj_", ".tmp");
        temp.deleteOnExit();
        IOUtils.copy(this.getClass().getResourceAsStream("xor.data"), new FileOutputStream(temp));
        List<Layer> layers = new ArrayList<Layer>();
        layers.add(Layer.create(2));
        layers.add(Layer.create(3, ActivationFunction.FANN_SIGMOID_SYMMETRIC));
        layers.add(Layer.create(1, ActivationFunction.FANN_SIGMOID_SYMMETRIC));
        Fann fann = new Fann(layers);
        Trainer trainer = new Trainer(fann);
        trainer.setTrainingAlgorithm(TrainingAlgorithm.FANN_TRAIN_QUICKPROP);
        float desiredError = .001f;
        float mse = trainer.train(temp.getPath(), 500000, 1000, desiredError);
        assertTrue("" + mse, mse <= desiredError);
    }
@Test
    public void testTrainingBackprop() throws IOException {
        File temp = File.createTempFile("fannj_", ".tmp");
        temp.deleteOnExit();
        IOUtils.copy(this.getClass().getResourceAsStream("xor.data"), new FileOutputStream(temp));
        List<Layer> layers = new ArrayList<Layer>();
        layers.add(Layer.create(2));
        layers.add(Layer.create(3, ActivationFunction.FANN_SIGMOID_SYMMETRIC));
        layers.add(Layer.create(2, ActivationFunction.FANN_SIGMOID_SYMMETRIC));
        layers.add(Layer.create(1, ActivationFunction.FANN_SIGMOID_SYMMETRIC));
        Fann fann = new Fann(layers);
        Trainer trainer = new Trainer(fann);
        trainer.setTrainingAlgorithm(TrainingAlgorithm.FANN_TRAIN_INCREMENTAL);
        float desiredError = .001f;
        float mse = trainer.train(temp.getPath(), 500000, 1000, desiredError);
        assertTrue("" + mse, mse <= desiredError);
    }
@Test
    public void testCascadeTraining() throws IOException {
        File temp = File.createTempFile("fannj_", ".tmp");
        temp.deleteOnExit();
        IOUtils.copy(this.getClass().getResourceAsStream("parity8.train"), new FileOutputStream(temp));
        Fann fann = new FannShortcut(8, 1);
        Trainer trainer = new Trainer(fann);
        float desiredError = .00f;
        float mse = trainer.cascadeTrain(temp.getPath(), 30, 1, desiredError);
        assertTrue("" + mse, mse <= desiredError);
    }
public static String SHA(String s) {
        try {
            MessageDigest md = MessageDigest.getInstance("SHA");
            md.update(s.getBytes(), 0, s.getBytes().length);
            byte[] hash = md.digest();
            StringBuilder sb = new StringBuilder();
            int msb;
            int lsb = 0;
            int i;
            for (i = 0; i < hash.length; i++) {
                msb = ((int) hash[i] & 0x000000FF) / 16;
                lsb = ((int) hash[i] & 0x000000FF) % 16;
                sb.append(hexChars[msb]);
                sb.append(hexChars[lsb]);
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            return null;
        }
    }
private void sendRemoteFiles() throws Exception {
        if (validParameters()) {
            URL url = new URL(storageUrlString);
            HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
            RequestUtils requestUtils = new RequestUtils();
            requestUtils.preRequestAddParameter("senderObj", "FileSender");
            requestUtils.preRequestAddParameter("wfiType", "zen");
            requestUtils.preRequestAddParameter("portalID", this.portalID);
            requestUtils.preRequestAddParameter("userID", this.userID);
            requestUtils.preRequestAddParameter("workflowID", this.workflowID);
            requestUtils.preRequestAddParameter("jobID", this.jobID);
            requestUtils.preRequestAddParameter("pidID", this.pidID);
            requestUtils.preRequestAddParameter("runtimeID", this.runtimeID);
            requestUtils.preRequestAddParameter("copyhash", getCopyHashStr());
            String zipFileName = ZipUtils.getInstance().getUniqueZipFileName();
            requestUtils.preRequestAddFile("zipFileName", zipFileName);
            requestUtils.createPostRequest();
            httpURLConnection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + requestUtils.getBoundary());
            httpURLConnection.setRequestMethod("POST");
            httpURLConnection.setDoOutput(true);
            httpURLConnection.setDoInput(true);
            try {
                httpURLConnection.connect();
                OutputStream out = httpURLConnection.getOutputStream();
                byte[] preBytes = requestUtils.getPreRequestStringBytes();
                out.write(preBytes);
                out.flush();
                ZipUtils.getInstance().sendDirAllFilesToStream(sendFilesDir, out);
                byte[] postBytes = requestUtils.getPostRequestStringBytes();
                out.write(postBytes);
                out.flush();
                out.close();
                BufferedReader in = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
                in.readLine();
                in.close();
                if (HttpURLConnection.HTTP_OK != httpURLConnection.getResponseCode()) {
                    throw new Exception("response not HTTP_OK !");
                }
            } catch (Exception e) {
                e.printStackTrace();
                throw new Exception("Cannot connect to: " + storageUrlString, e);
            }
        } else {
            throw new Exception("FilesDir not exist ! or not valid parameters: portalID, userID, workflowID, jobID, pidID, runtimeID !");
        }
    }
@SuppressWarnings("static-access")
    @RequestMapping(value = "/upload/upload.html", method = RequestMethod.POST)
    protected void save(HttpServletRequest request, HttpServletResponse response) throws ServletException {
        UPLOAD_DIRECTORY = uploadDiretory();
        File diretorioUsuario = new File(UPLOAD_DIRECTORY);
        boolean diretorioCriado = false;
        if (!diretorioUsuario.exists()) {
            diretorioCriado = diretorioUsuario.mkdir();
            if (!diretorioCriado) throw new RuntimeException("Não foi possível criar o diretório do usuário");
        }
        PrintWriter writer = null;
        InputStream is = null;
        FileOutputStream fos = null;
        try {
            writer = response.getWriter();
        } catch (IOException ex) {
            System.err.println(FileUploadController.class.getName() + "has thrown an exception: " + ex.getMessage());
        }
        String filename = request.getHeader("X-File-Name");
        try {
            is = request.getInputStream();
            fos = new FileOutputStream(new File(UPLOAD_DIRECTORY + filename));
            IOUtils.copy(is, fos);
            response.setStatus(response.SC_OK);
            writer.print("{success: true}");
        } catch (FileNotFoundException ex) {
            response.setStatus(response.SC_INTERNAL_SERVER_ERROR);
            writer.print("{success: false}");
            System.err.println(FileUploadController.class.getName() + "has thrown an exception: " + ex.getMessage());
        } catch (IOException ex) {
            response.setStatus(response.SC_INTERNAL_SERVER_ERROR);
            writer.print("{success: false}");
            System.err.println(FileUploadController.class.getName() + "has thrown an exception: " + ex.getMessage());
        } finally {
            try {
                fos.close();
                is.close();
            } catch (IOException ignored) {
            }
        }
        writer.flush();
        writer.close();
    }
public String md5(String phrase) {
        MessageDigest m;
        String coded = new String();
        try {
            m = MessageDigest.getInstance("MD5");
            m.update(phrase.getBytes(), 0, phrase.length());
            coded = (new BigInteger(1, m.digest()).toString(16)).toString();
        } catch (NoSuchAlgorithmException ex) {
            ex.printStackTrace();
        }
        return coded;
    }
public void serviceDocument(final TranslationRequest request, final TranslationResponse response, final Document document) throws Exception {
        response.addHeaders(document.getResponseHeaders());
        try {
            IOUtils.copy(document.getInputStream(), response.getOutputStream());
            response.setEndState(ResponseStateOk.getInstance());
        } catch (Exception e) {
            response.setEndState(new ResponseStateException(e));
            log.warn("Error parsing XML of " + document, e);
        }
    }
public JavaCodeAnalyzer(String filenameIn, String filenameOut, String lineLength) {
        try {
            File tmp = File.createTempFile("JavaCodeAnalyzer", "tmp");
            BufferedReader br = new BufferedReader(new FileReader(filenameIn));
            BufferedWriter out = new BufferedWriter(new FileWriter(tmp));
            while (br.ready()) {
                out.write(br.read());
            }
            br.close();
            out.close();
            jco = new JavaCodeOutput(tmp, filenameOut, lineLength);
            SourceCodeParser p = new JavaCCParserFactory().createParser(new FileReader(tmp), null);
            List statements = p.parseCompilationUnit();
            ListIterator it = statements.listIterator();
            eh = new ExpressionHelper(this, jco);
            Node n;
            printLog("Parsed file " + filenameIn + "\n");
            while (it.hasNext()) {
                n = (Node) it.next();
                parseObject(n);
            }
            tmp.delete();
        } catch (Exception e) {
            System.err.println(getClass() + ": " + e);
        }
    }
private void populateSessionId() throws IOException, java.net.MalformedURLException {
        String general_search_url = "http://agricola.nal.usda.gov/cgi-bin/Pwebrecon.cgi?" + "DB=local&CNT=1&Search_Arg=RNAi&Search_Code=GKEY&STARTDB=AGRIDB";
        String sidString = "", inputLine;
        BufferedReader in = new BufferedReader(new InputStreamReader((new URL(general_search_url)).openStream()));
        while ((inputLine = in.readLine()) != null) {
            if (inputLine.startsWith("<INPUT TYPE=HIDDEN NAME=PID VALUE=")) {
                sidString = (inputLine.substring(inputLine.indexOf("PID VALUE=") + 11, inputLine.indexOf(">") - 1));
            }
        }
        sessionId = Integer.parseInt(sidString.trim());
    }
private List parseUrlGetUids(String url) throws FetchError {
        List hids = new ArrayList();
        try {
            InputStream is = (new URL(url)).openStream();
            BufferedReader in = new BufferedReader(new InputStreamReader(is));
            StringBuffer buffer = new StringBuffer();
            String inputLine = "";
            Pattern pattern = Pattern.compile("\\<input\\s+type=hidden\\s+name=hid\\s+value=(\\d+)\\s?\\>", Pattern.CASE_INSENSITIVE);
            while ((inputLine = in.readLine()) != null) {
                Matcher matcher = pattern.matcher(inputLine);
                if (matcher.find()) {
                    String id = matcher.group(1);
                    if (!hids.contains(id)) {
                        hids.add(id);
                    }
                }
            }
        } catch (Exception e) {
            System.out.println(e);
            throw new FetchError(e);
        }
        return hids;
    }
public static int getNetFileSize(String netFile) throws InvalidActionException {
        URL url;
        URLConnection conn;
        int size;
        try {
            url = new URL(netFile);
            conn = url.openConnection();
            size = conn.getContentLength();
            conn.getInputStream().close();
            if (size < 0) {
                throw new InvalidActionException("Could not determine file size.");
            } else {
                return size;
            }
        } catch (Exception e) {
            throw new InvalidActionException(e.getMessage());
        }
    }
public static ArrayList<Quote> fetchAllQuotes(String symbol, Date from, Date to) {
        try {
            GregorianCalendar calendar = new GregorianCalendar();
            calendar.setTime(from);
            String monthFrom = (new Integer(calendar.get(GregorianCalendar.MONTH))).toString();
            String dayFrom = (new Integer(calendar.get(GregorianCalendar.DAY_OF_MONTH))).toString();
            String yearFrom = (new Integer(calendar.get(GregorianCalendar.YEAR))).toString();
            calendar.setTime(to);
            String monthTo = (new Integer(calendar.get(GregorianCalendar.MONTH))).toString();
            String dayTo = (new Integer(calendar.get(GregorianCalendar.DAY_OF_MONTH))).toString();
            String yearTo = (new Integer(calendar.get(GregorianCalendar.YEAR))).toString();
            URL url = new URL("http://ichart.finance.yahoo.com/table.csv?s=" + symbol + "&a=" + monthFrom + "&b=" + dayFrom + "&c=" + yearFrom + "&d=" + monthTo + "&e=" + dayTo + "&f=" + yearTo + "&g=d&ignore=.csv");
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            ArrayList<Quote> result = new ArrayList<Quote>();
            reader.readLine();
            while ((line = reader.readLine()) != null) {
                String[] values = line.split(",");
                String date = values[0];
                Date dateQuote = new SimpleDateFormat("yyyy-MM-dd").parse(date);
                double open = Double.valueOf(values[1]);
                double high = Double.valueOf(values[2]);
                double low = Double.valueOf(values[3]);
                double close = Double.valueOf(values[4]);
                long volume = Long.valueOf(values[5]);
                double adjClose = Double.valueOf(values[6]);
                Quote q = new Quote(dateQuote, open, high, low, close, volume, adjClose);
                result.add(q);
            }
            reader.close();
            Collections.reverse(result);
            return result;
        } catch (MalformedURLException e) {
            System.out.println("URL malformee");
        } catch (IOException e) {
            System.out.println("Donnees illisibles");
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }
@Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        final EditText eText = (EditText) findViewById(R.id.address);
        final Button button = (Button) findViewById(R.id.ButtonGo);
        button.setOnClickListener(new Button.OnClickListener() {

            public void onClick(View v) {
                try {
                    HttpClient httpclient = new DefaultHttpClient();
                    HttpPost httppost = new HttpPost("https://mt0-app.cloud.cm/rpc/json");
                    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                    nameValuePairs.add(new BasicNameValuePair("m", "login"));
                    nameValuePairs.add(new BasicNameValuePair("c", "User"));
                    nameValuePairs.add(new BasicNameValuePair("password", "cloudisgreat"));
                    nameValuePairs.add(new BasicNameValuePair("alias", "cs588"));
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                    String result = "";
                    try {
                        HttpResponse response = httpclient.execute(httppost);
                        result = EntityUtils.toString(response.getEntity());
                    } catch (Exception e) {
                        result = e.getMessage();
                    }
                    LayoutInflater inflater = (LayoutInflater) WebTest.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    final View layout = inflater.inflate(R.layout.window1, null);
                    final PopupWindow popup = new PopupWindowTest(layout, 100, 100);
                    Button b = (Button) layout.findViewById(R.id.test_button);
                    b.setOnTouchListener(new OnTouchListener() {

                        @Override
                        public boolean onTouch(View v, MotionEvent event) {
                            Log.d("Debug", "Button activate");
                            popup.dismiss();
                            return false;
                        }
                    });
                    popup.showAtLocation(layout, Gravity.CENTER, 0, 0);
                    View layout2 = inflater.inflate(R.layout.window1, null);
                    final PopupWindow popup2 = new PopupWindowTest(layout2, 100, 100);
                    TextView tview = (TextView) layout2.findViewById(R.id.pagetext);
                    tview.setText(result);
                    popup2.showAtLocation(layout, Gravity.CENTER, 50, -90);
                } catch (Exception e) {
                    Log.d("Debug", e.toString());
                }
            }
        });
    }
public void onClick(View v) {
                try {
                    HttpClient httpclient = new DefaultHttpClient();
                    HttpPost httppost = new HttpPost("https://mt0-app.cloud.cm/rpc/json");
                    List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
                    nameValuePairs.add(new BasicNameValuePair("m", "login"));
                    nameValuePairs.add(new BasicNameValuePair("c", "User"));
                    nameValuePairs.add(new BasicNameValuePair("password", "cloudisgreat"));
                    nameValuePairs.add(new BasicNameValuePair("alias", "cs588"));
                    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
                    String result = "";
                    try {
                        HttpResponse response = httpclient.execute(httppost);
                        result = EntityUtils.toString(response.getEntity());
                    } catch (Exception e) {
                        result = e.getMessage();
                    }
                    LayoutInflater inflater = (LayoutInflater) WebTest.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
                    final View layout = inflater.inflate(R.layout.window1, null);
                    final PopupWindow popup = new PopupWindowTest(layout, 100, 100);
                    Button b = (Button) layout.findViewById(R.id.test_button);
                    b.setOnTouchListener(new OnTouchListener() {

                        @Override
                        public boolean onTouch(View v, MotionEvent event) {
                            Log.d("Debug", "Button activate");
                            popup.dismiss();
                            return false;
                        }
                    });
                    popup.showAtLocation(layout, Gravity.CENTER, 0, 0);
                    View layout2 = inflater.inflate(R.layout.window1, null);
                    final PopupWindow popup2 = new PopupWindowTest(layout2, 100, 100);
                    TextView tview = (TextView) layout2.findViewById(R.id.pagetext);
                    tview.setText(result);
                    popup2.showAtLocation(layout, Gravity.CENTER, 50, -90);
                } catch (Exception e) {
                    Log.d("Debug", e.toString());
                }
            }