semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static byte[] sendParamPost(String urlString, String param) {
        try {
            URL url = new URL(urlString + "?" + param);
            HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
            urlConn.setDoOutput(true);
            urlConn.setDefaultUseCaches(false);
            urlConn.setDoInput(true);
            urlConn.setRequestMethod("POST");
            urlConn.connect();
            OutputStream ops = urlConn.getOutputStream();
            ops.close();
            InputStream is = urlConn.getInputStream();
            byte[] resultBytes = new byte[urlConn.getContentLength()];
            byte[] tempByte = new byte[1024];
            int length = 0;
            int index = 0;
            while ((length = is.read(tempByte)) != -1) {
                System.arraycopy(tempByte, 0, resultBytes, index, length);
                index += length;
            }
            is.close();
            return resultBytes;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }
public final void propertyChange(final PropertyChangeEvent event) {
        if (fChecker != null && event.getProperty().equals(ISpellCheckPreferenceKeys.SPELLING_USER_DICTIONARY)) {
            if (fUserDictionary != null) {
                fChecker.removeDictionary(fUserDictionary);
                fUserDictionary = null;
            }
            final String file = (String) event.getNewValue();
            if (file.length() > 0) {
                try {
                    final URL url = new URL("file", null, file);
                    InputStream stream = url.openStream();
                    if (stream != null) {
                        try {
                            fUserDictionary = new PersistentSpellDictionary(url);
                            fChecker.addDictionary(fUserDictionary);
                        } finally {
                            stream.close();
                        }
                    }
                } catch (MalformedURLException exception) {
                } catch (IOException exception) {
                }
            }
        }
    }
private static void copyFile(String src, String dest) {
        try {
            File inputFile = new File(src);
            File outputFile = new File(dest);
            FileInputStream in = new FileInputStream(inputFile);
            FileOutputStream out = new FileOutputStream(outputFile);
            FileChannel inc = in.getChannel();
            FileChannel outc = out.getChannel();
            inc.transferTo(0, inc.size(), outc);
            inc.close();
            outc.close();
            in.close();
            out.close();
        } catch (Exception e) {
        }
    }
public void setFlag(Flags.Flag oFlg, boolean bFlg) throws MessagingException {
        String sColunm;
        super.setFlag(oFlg, bFlg);
        if (oFlg.equals(Flags.Flag.ANSWERED)) sColunm = DB.bo_answered; else if (oFlg.equals(Flags.Flag.DELETED)) sColunm = DB.bo_deleted; else if (oFlg.equals(Flags.Flag.DRAFT)) sColunm = DB.bo_draft; else if (oFlg.equals(Flags.Flag.FLAGGED)) sColunm = DB.bo_flagged; else if (oFlg.equals(Flags.Flag.RECENT)) sColunm = DB.bo_recent; else if (oFlg.equals(Flags.Flag.SEEN)) sColunm = DB.bo_seen; else sColunm = null;
        if (null != sColunm && oFolder instanceof DBFolder) {
            JDCConnection oConn = null;
            PreparedStatement oUpdt = null;
            try {
                oConn = ((DBFolder) oFolder).getConnection();
                String sSQL = "UPDATE " + DB.k_mime_msgs + " SET " + sColunm + "=" + (bFlg ? "1" : "0") + " WHERE " + DB.gu_mimemsg + "='" + getMessageGuid() + "'";
                if (DebugFile.trace) DebugFile.writeln("Connection.prepareStatement(" + sSQL + ")");
                oUpdt = oConn.prepareStatement(sSQL);
                oUpdt.executeUpdate();
                oUpdt.close();
                oUpdt = null;
                oConn.commit();
                oConn = null;
            } catch (SQLException e) {
                if (null != oConn) {
                    try {
                        oConn.rollback();
                    } catch (Exception ignore) {
                    }
                }
                if (null != oUpdt) {
                    try {
                        oUpdt.close();
                    } catch (Exception ignore) {
                    }
                }
                if (DebugFile.trace) DebugFile.decIdent();
                throw new MessagingException(e.getMessage(), e);
            }
        }
    }
public GPSTrace loadGPSTrace(long reportID) {
        try {
            URL url = new URL(SERVER_URL + XML_PATH + "gps.xml");
            System.out.println(url);
            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
            DocumentBuilder builder = factory.newDocumentBuilder();
            document = builder.parse(url.openStream());
            Element customerElement = document.getDocumentElement();
            NodeList gps = customerElement.getElementsByTagName("gps");
            trace = getGPSTrace(gps);
        } catch (SAXException sxe) {
            Exception x = sxe;
            if (sxe.getException() != null) x = sxe.getException();
            x.printStackTrace();
        } catch (ParserConfigurationException pce) {
            pce.printStackTrace();
        } catch (IOException ioe) {
            ioe.printStackTrace();
        }
        return trace;
    }
private EventSeries<PhotoEvent> loadIncomingEvents(long reportID) {
        EventSeries<PhotoEvent> events = new EventSeries<PhotoEvent>();
        try {
            URL url = new URL(SERVER_URL + XML_PATH + "reports.csv");
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String str;
            while ((str = reader.readLine()) != null) {
                String[] values = str.split(",");
                if (values.length == 2) {
                    long id = Long.parseLong(values[0]);
                    if (id == reportID) {
                        long time = Long.parseLong(values[1]);
                        events.addEvent(new PhotoEvent(time));
                    }
                }
            }
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return events;
    }
private void copy(File sourceFile, File destinationFile) {
        try {
            FileChannel in = new FileInputStream(sourceFile).getChannel();
            FileChannel out = new FileOutputStream(destinationFile).getChannel();
            try {
                in.transferTo(0, in.size(), out);
                in.close();
                out.close();
            } catch (IOException e) {
                TestLogger.error(e);
            }
        } catch (FileNotFoundException e) {
            TestLogger.error(e);
        }
    }
public static ArrayList<String> remoteCall(Map<String, String> dataDict) {
        ArrayList<String> result = new ArrayList<String>();
        String encodedData = "";
        for (String key : dataDict.keySet()) {
            String encodedSegment = "";
            String value = dataDict.get(key);
            if (value == null) continue;
            try {
                encodedSegment = key + "=" + URLEncoder.encode(value, "UTF-8");
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
            if (encodedData.length() > 0) {
                encodedData += "&";
            }
            encodedData += encodedSegment;
        }
        try {
            URL url = new URL(baseURL + encodedData);
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String line;
            while ((line = reader.readLine()) != null) {
                result.add(line);
                System.out.println("GOT: " + line);
            }
            reader.close();
            result.remove(0);
            if (result.size() != 0) {
                if (!result.get(result.size() - 1).equals("DONE")) {
                    result.clear();
                } else {
                    result.remove(result.size() - 1);
                }
            }
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
        return result;
    }
@Test
    public void test_baseMaterialsForTypeID_NonExistingID() throws Exception {
        URL url = new URL(baseUrl + "/baseMaterialsForTypeID/1234567890");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/json");
        assertThat(connection.getResponseCode(), equalTo(400));
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/xml");
        assertThat(connection.getResponseCode(), equalTo(400));
    }
@Test
    public void test_baseMaterialsForTypeID_StringInsteadOfID() throws Exception {
        URL url = new URL(baseUrl + "/baseMaterialsForTypeID/blah-blah");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/json");
        assertThat(connection.getResponseCode(), equalTo(400));
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/xml");
        assertThat(connection.getResponseCode(), equalTo(400));
    }
@Test
    public void test_baseMaterialsForTypeName_NonExistingName() throws Exception {
        URL url = new URL(baseUrl + "/baseMaterialsForTypeName/blah-blah");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/json");
        assertThat(connection.getResponseCode(), equalTo(400));
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/xml");
        assertThat(connection.getResponseCode(), equalTo(400));
    }
@Test
    public void test_blueprintTypeByTypeID() throws Exception {
        URL url = new URL(baseUrl + "/blueprintTypeByTypeID/20188");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/json");
        assertThat(connection.getResponseCode(), equalTo(200));
        assertThat(getResponse(connection), equalTo("{\"blueprintTypeID\":20188,\"blueprintTypeName\":\"Obelisk Blueprint\",\"productTypeID\":20187,\"productTypeName\":\"Obelisk\",\"productCategoryID\":6,\"techLevel\":1,\"productionTime\":1280000,\"researchProductivityTime\":7680000,\"researchMaterialTime\":5120000,\"researchCopyTime\":2560000,\"researchTechTime\":500000,\"productivityModifier\":256000,\"wasteFactor\":10,\"maxProductionLimit\":1,\"productVolume\":\"17550000\",\"productPortionSize\":1,\"dumpVersion\":\"cru16\"}"));
        assertThat(connection.getHeaderField("Content-Type"), equalTo("application/json; charset=utf-8"));
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/xml");
        assertThat(connection.getResponseCode(), equalTo(200));
        assertThat(getResponse(connection), equalTo("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><invBlueprintTypeDto><blueprintTypeID>20188</blueprintTypeID><blueprintTypeName>Obelisk Blueprint</blueprintTypeName><dumpVersion>cru16</dumpVersion><maxProductionLimit>1</maxProductionLimit><productCategoryID>6</productCategoryID><productPortionSize>1</productPortionSize><productTypeID>20187</productTypeID><productTypeName>Obelisk</productTypeName><productVolume>17550000</productVolume><productionTime>1280000</productionTime><productivityModifier>256000</productivityModifier><researchCopyTime>2560000</researchCopyTime><researchMaterialTime>5120000</researchMaterialTime><researchProductivityTime>7680000</researchProductivityTime><researchTechTime>500000</researchTechTime><techLevel>1</techLevel><wasteFactor>10</wasteFactor></invBlueprintTypeDto>"));
        assertThat(connection.getHeaderField("Content-Type"), equalTo("application/xml; charset=utf-8"));
    }
@Test
    public void test_blueprintTypeByTypeID_NonExistingID() throws Exception {
        URL url = new URL(baseUrl + "/blueprintTypeByTypeID/1234567890");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/json");
        assertThat(connection.getResponseCode(), equalTo(400));
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/xml");
        assertThat(connection.getResponseCode(), equalTo(400));
    }
@Test
    public void test_blueprintTypeByTypeID_StringInsteadOfID() throws Exception {
        URL url = new URL(baseUrl + "/blueprintTypeByTypeID/blah-blah");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/json");
        assertThat(connection.getResponseCode(), equalTo(400));
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/xml");
        assertThat(connection.getResponseCode(), equalTo(400));
    }
@Test
    public void test_lookupResourceType_FullSearch_MatchingWordInMiddle() throws Exception {
        URL url = new URL(baseUrl + "/lookupResourceType/carbo");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/json");
        assertThat(connection.getResponseCode(), equalTo(200));
        assertThat(getResponse(connection), equalTo("[{\"itemTypeID\":16659,\"itemCategoryID\":4,\"name\":\"Carbon Polymers\",\"icon\":\"50_04\"},{\"itemTypeID\":30310,\"itemCategoryID\":4,\"name\":\"Carbon-86 Epoxy Resin\",\"icon\":\"83_10\"},{\"itemTypeID\":16670,\"itemCategoryID\":4,\"name\":\"Crystalline Carbonide\",\"icon\":\"49_09\"}]"));
        assertThat(connection.getHeaderField("Content-Type"), equalTo("application/json; charset=utf-8"));
    }
@Test
    public void test_lookupResourceType_FullSearch_TwoWords() throws Exception {
        URL url = new URL(baseUrl + "/lookupResourceType/alloyed+tritanium");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/json");
        assertThat(connection.getResponseCode(), equalTo(200));
        assertThat(getResponse(connection), equalTo("[{\"itemTypeID\":25595,\"itemCategoryID\":4,\"name\":\"Alloyed Tritanium Bar\",\"icon\":\"69_11\"}]"));
        assertThat(connection.getHeaderField("Content-Type"), equalTo("application/json; charset=utf-8"));
    }
@Test
    public void test_lookupResourceType_FullSearch_TwoWordsInMiddle() throws Exception {
        URL url = new URL(baseUrl + "/lookupResourceType/armor+plates");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/json");
        assertThat(connection.getResponseCode(), equalTo(200));
        assertThat(getResponse(connection), equalTo("[{\"itemTypeID\":25605,\"itemCategoryID\":4,\"name\":\"Armor Plates\",\"icon\":\"69_09\"},{\"itemTypeID\":25624,\"itemCategoryID\":4,\"name\":\"Intact Armor Plates\",\"icon\":\"69_10\"}]"));
        assertThat(connection.getHeaderField("Content-Type"), equalTo("application/json; charset=utf-8"));
    }
@Test
    public void test_lookupType_NonExistingName() throws Exception {
        URL url = new URL(baseUrl + "/lookupType/blah-blah");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/json");
        assertThat(connection.getResponseCode(), equalTo(200));
        assertThat(getResponse(connection), equalTo("[]"));
        assertThat(connection.getHeaderField("Content-Type"), equalTo("application/json; charset=utf-8"));
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/xml");
        assertThat(connection.getResponseCode(), equalTo(200));
        assertThat(getResponse(connection), equalTo("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><rowset/>"));
        assertThat(connection.getHeaderField("Content-Type"), equalTo("application/xml; charset=utf-8"));
    }
@Test
    public void test_lookupType_TooShortName() throws Exception {
        URL url = new URL(baseUrl + "/lookupType/A");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/json");
        assertThat(connection.getResponseCode(), equalTo(400));
        connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/xml");
        assertThat(connection.getResponseCode(), equalTo(400));
    }
@Test
    public void test_lookupType_FullSearch_CaseSensivity() throws Exception {
        URL url = new URL(baseUrl + "/lookupType/moRO");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/json");
        assertThat(connection.getResponseCode(), equalTo(200));
        assertThat(getResponse(connection), equalTo("[{\"itemTypeID\":19724,\"itemCategoryID\":6,\"name\":\"Moros\"},{\"itemTypeID\":19725,\"itemCategoryID\":9,\"name\":\"Moros Blueprint\"}]"));
        assertThat(connection.getHeaderField("Content-Type"), equalTo("application/json; charset=utf-8"));
    }
@Test
    public void test_lookupType_FullSearch_TwoWords() throws Exception {
        URL url = new URL(baseUrl + "/lookupType/deep+core");
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("GET");
        connection.setRequestProperty("Accept", "application/json");
        assertThat(connection.getResponseCode(), equalTo(200));
        assertThat(getResponse(connection), equalTo("[{\"itemTypeID\":11395,\"itemCategoryID\":16,\"name\":\"Deep Core Mining\",\"icon\":\"50_11\"},{\"itemTypeID\":12108,\"itemCategoryID\":7,\"name\":\"Deep Core Mining Laser I\",\"icon\":\"35_01\",\"metaLevel\":0},{\"itemTypeID\":12109,\"itemCategoryID\":9,\"name\":\"Deep Core Mining Laser I Blueprint\",\"icon\":\"12_08\"},{\"itemTypeID\":18068,\"itemCategoryID\":7,\"name\":\"Modulated Deep Core Miner II\",\"icon\":\"35_01\",\"metaLevel\":5},{\"itemTypeID\":18069,\"itemCategoryID\":9,\"name\":\"Modulated Deep Core Miner II Blueprint\",\"icon\":\"12_08\"},{\"itemTypeID\":24305,\"itemCategoryID\":7,\"name\":\"Modulated Deep Core Strip Miner II\",\"icon\":\"49_05\",\"metaLevel\":5},{\"itemTypeID\":24306,\"itemCategoryID\":9,\"name\":\"Modulated Deep Core Strip Miner II Blueprint\",\"icon\":\"12_08\"},{\"itemTypeID\":28748,\"itemCategoryID\":7,\"name\":\"ORE Deep Core Mining Laser\",\"icon\":\"35_01\",\"metaLevel\":6}]"));
        assertThat(connection.getHeaderField("Content-Type"), equalTo("application/json; charset=utf-8"));
    }
public String getResponse(String URLstring) {
        String str = "";
        try {
            URL url = new URL(URLstring);
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String st = "";
            while ((st = in.readLine()) != null) {
                str += "\n" + st;
            }
            in.close();
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
        return str;
    }
public void access() {
        Authenticator.setDefault(new MyAuthenticator());
        try {
            URL url = new URL("http://localhost/ws/test");
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String str;
            while ((str = in.readLine()) != null) {
            }
            in.close();
        } catch (MalformedURLException e) {
        } catch (IOException e) {
        }
    }
public void uncaughtException(final Thread t, final Throwable e) {
        final Display display = Display.getCurrent();
        final Shell shell = new Shell(display);
        final MessageBox message = new MessageBox(shell, SWT.OK | SWT.CANCEL | SWT.ICON_ERROR);
        message.setText("Hawkscope Error");
        message.setMessage(e.getMessage() + "\nSubmit Hawkscope Error Report to Issue Tracker?");
        log.error("Uncaught exception", e);
        if (message.open() == SWT.OK) {
            IOUtils.copyToClipboard(Version.getBugReport(e));
            try {
                Program.launch(Constants.HAWKSCOPE_URL_ROOT + "issues/entry?comment=" + URLEncoder.encode("Please paste the Hawkscope Error " + "Report here. It's currently copied to your " + "clipboard. Thank you for your support!", Constants.ENCODING));
            } catch (final Exception e1) {
                Program.launch(Constants.HAWKSCOPE_URL_ROOT + "issues/entry");
            }
        }
        shell.dispose();
    }
public static InputStream call(String serviceUrl, Map parameters) throws IOException, RestException {
        StringBuffer urlString = new StringBuffer(serviceUrl);
        String query = RestClient.buildQueryString(parameters);
        HttpURLConnection conn;
        if ((urlString.length() + query.length() + 1) > MAX_URI_LENGTH_FOR_GET) {
            URL url = new URL(urlString.toString());
            conn = (HttpURLConnection) url.openConnection();
            conn.setRequestProperty("User-Agent", USER_AGENT_STRING);
            conn.setRequestMethod("POST");
            conn.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
            conn.setDoOutput(true);
            conn.getOutputStream().write(query.getBytes());
        } else {
            if (query.length() > 0) {
                urlString.append("?").append(query);
            }
            URL url = new URL(urlString.toString());
            conn = (HttpURLConnection) url.openConnection();
            conn.setRequestProperty("User-Agent", USER_AGENT_STRING);
            conn.setRequestMethod("GET");
        }
        int responseCode = conn.getResponseCode();
        if (HttpURLConnection.HTTP_OK != responseCode) {
            ByteArrayOutputStream errorBuffer = new ByteArrayOutputStream();
            int read;
            byte[] readBuffer = new byte[ERROR_READ_BUFFER_SIZE];
            InputStream errorStream = conn.getErrorStream();
            while (-1 != (read = errorStream.read(readBuffer))) {
                errorBuffer.write(readBuffer, 0, read);
            }
            throw new RestException("Request failed, HTTP " + responseCode + ": " + conn.getResponseMessage(), errorBuffer.toByteArray());
        }
        return conn.getInputStream();
    }