semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public static void main(String[] args) {
        try {
            String user = "techbeherca";
            String targetUrl = "http://api.fanfou.com/statuses/user_timeline.xml?id=" + user;
            URL url = new URL(targetUrl);
            InputStream in = url.openStream();
            ArrayList<MessageObj> list;
            if (in != null) {
                MessageListDOMParser parser = new MessageListDOMParser();
                list = (ArrayList<MessageObj>) parser.parseXML(in);
                TransactionDAO dao = new TransactionDAO();
                dao.insert(list);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
public static boolean copyfile(String file0, String file1) {
        try {
            File f0 = new File(file0);
            File f1 = new File(file1);
            FileInputStream in = new FileInputStream(f0);
            FileOutputStream out = new FileOutputStream(f1);
            int c;
            while ((c = in.read()) != -1) out.write(c);
            in.close();
            out.close();
            in = null;
            out = null;
            return true;
        } catch (Exception e) {
            return false;
        }
    }
public void testJTLM_publish911() throws Exception {
        EXISchema corpus = EXISchemaFactoryTestUtil.getEXISchema("/JTLM/schemas/TLMComposite.xsd", getClass(), m_compilerErrors);
        Assert.assertEquals(0, m_compilerErrors.getTotalCount());
        GrammarCache grammarCache = new GrammarCache(corpus, GrammarOptions.STRICT_OPTIONS);
        AlignmentType alignment = AlignmentType.compress;
        Transmogrifier encoder = new Transmogrifier();
        EXIDecoder decoder = new EXIDecoder();
        Scanner scanner;
        InputSource inputSource;
        encoder.setAlignmentType(alignment);
        decoder.setAlignmentType(alignment);
        encoder.setEXISchema(grammarCache);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        encoder.setOutputStream(baos);
        URL url = resolveSystemIdAsURL("/JTLM/publish911.xml");
        inputSource = new InputSource(url.toString());
        inputSource.setByteStream(url.openStream());
        byte[] bts;
        int n_events, n_texts;
        encoder.encode(inputSource);
        bts = baos.toByteArray();
        decoder.setEXISchema(grammarCache);
        decoder.setInputStream(new ByteArrayInputStream(bts));
        scanner = decoder.processHeader();
        ArrayList<EXIEvent> exiEventList = new ArrayList<EXIEvent>();
        EXIEvent exiEvent;
        n_events = 0;
        n_texts = 0;
        while ((exiEvent = scanner.nextEvent()) != null) {
            ++n_events;
            if (exiEvent.getEventVariety() == EXIEvent.EVENT_CH) {
                if (exiEvent.getCharacters().length() == 0) {
                    --n_events;
                    continue;
                }
                if (n_texts % 100 == 0) {
                    final int n = n_texts / 100;
                    Assert.assertEquals(JTLMTest.publish911_centennials[n], exiEvent.getCharacters().makeString());
                }
                ++n_texts;
            }
            exiEventList.add(exiEvent);
        }
        Assert.assertEquals(96576, n_events);
    }
public void testJTLM_publish100_blockSize() throws Exception {
        EXISchema corpus = EXISchemaFactoryTestUtil.getEXISchema("/JTLM/schemas/TLMComposite.xsd", getClass(), m_compilerErrors);
        Assert.assertEquals(0, m_compilerErrors.getTotalCount());
        GrammarCache grammarCache = new GrammarCache(corpus, GrammarOptions.STRICT_OPTIONS);
        AlignmentType[] alignments = new AlignmentType[] { AlignmentType.preCompress, AlignmentType.compress };
        int[] blockSizes = { 1, 100, 101 };
        Transmogrifier encoder = new Transmogrifier();
        EXIDecoder decoder = new EXIDecoder(999);
        encoder.setOutputOptions(HeaderOptionsOutputType.lessSchemaId);
        encoder.setEXISchema(grammarCache);
        decoder.setEXISchema(grammarCache);
        for (AlignmentType alignment : alignments) {
            for (int i = 0; i < blockSizes.length; i++) {
                Scanner scanner;
                InputSource inputSource;
                encoder.setAlignmentType(alignment);
                encoder.setBlockSize(blockSizes[i]);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                encoder.setOutputStream(baos);
                URL url = resolveSystemIdAsURL("/JTLM/publish100.xml");
                inputSource = new InputSource(url.toString());
                inputSource.setByteStream(url.openStream());
                byte[] bts;
                int n_events, n_texts;
                encoder.encode(inputSource);
                bts = baos.toByteArray();
                decoder.setInputStream(new ByteArrayInputStream(bts));
                scanner = decoder.processHeader();
                ArrayList<EXIEvent> exiEventList = new ArrayList<EXIEvent>();
                EXIEvent exiEvent;
                n_events = 0;
                n_texts = 0;
                while ((exiEvent = scanner.nextEvent()) != null) {
                    ++n_events;
                    if (exiEvent.getEventVariety() == EXIEvent.EVENT_CH) {
                        if (exiEvent.getCharacters().length() == 0) {
                            --n_events;
                            continue;
                        }
                        if (n_texts % 100 == 0) {
                            final int n = n_texts / 100;
                            Assert.assertEquals(JTLMTest.publish100_centennials[n], exiEvent.getCharacters().makeString());
                        }
                        ++n_texts;
                    }
                    exiEventList.add(exiEvent);
                }
                Assert.assertEquals(10610, n_events);
            }
        }
    }
private HashSet<String> loadSupportedAnnotationTypes(VannitationType baseVannitationType) {
        Enumeration<URL> urls = null;
        try {
            urls = this.getClass().getClassLoader().getResources("META-INF/" + baseVannitationType);
        } catch (IOException e) {
            throw new RuntimeException("Failed to load the annotations we support", e);
        }
        supportedAnnotationTypes.put(baseVannitationType, new HashSet<String>());
        while (urls.hasMoreElements()) {
            URL url = urls.nextElement();
            try {
                BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
                String line;
                while ((line = reader.readLine()) != null) {
                    supportedAnnotationTypes.get(baseVannitationType).add(line.trim());
                }
                reader.close();
            } catch (Exception e) {
                throw new RuntimeException("Could not open " + url);
            }
        }
        return supportedAnnotationTypes.get(baseVannitationType);
    }
private Properties getProperties(URL url) throws java.io.IOException {
            Properties cdrList = new Properties();
            java.io.InputStream stream = url.openStream();
            cdrList.load(stream);
            stream.close();
            return cdrList;
        }
@Override
        public void run() {
            long timeout = 10 * 1000L;
            long start = (new Date()).getTime();
            try {
                InputStream is = socket.getInputStream();
                boolean available = false;
                while (!available && !socket.isClosed()) {
                    try {
                        if (is.available() != 0) {
                            available = true;
                        } else {
                            Thread.sleep(100);
                        }
                    } catch (Exception e) {
                        LOG.error("Error checking socket", e);
                    }
                    long curr = (new Date()).getTime();
                    if ((curr - start) >= timeout) {
                        break;
                    }
                }
                if (socket.isClosed()) {
                } else {
                    tmpFile = File.createTempFile("ftp", "dat", new File("./tmp"));
                    BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(tmpFile));
                    IOUtils.copy(is, bos);
                    bos.flush();
                    bos.close();
                }
                String msg = FtpResponse.ReadComplete.asString() + ClientCommand.SP + "Read Complete" + ClientCommand.CRLF;
                List<String> list = new ArrayList<String>();
                list.add(msg);
                ClientResponse response = new ClientResponse(list);
                ftpClient.notifyListeners(response);
            } catch (Exception e) {
                LOG.error("Error reading server response", e);
            }
        }
@Override
        public void run() {
            long timeout = 10 * 1000L;
            long start = (new Date()).getTime();
            try {
                InputStream is = socket.getInputStream();
                boolean available = false;
                while (!available && !socket.isClosed()) {
                    try {
                        if (is.available() != 0) {
                            available = true;
                        } else {
                            Thread.sleep(100);
                        }
                    } catch (Exception e) {
                        LOG.error("Error checking socket", e);
                    }
                    long curr = (new Date()).getTime();
                    if ((curr - start) >= timeout) {
                        break;
                    }
                }
                if (socket.isClosed()) {
                } else {
                    ByteArrayOutputStream baos = new ByteArrayOutputStream();
                    IOUtils.copy(is, baos);
                    baos.flush();
                    baos.close();
                    data = baos.toByteArray();
                }
                String msg = FtpResponse.ReadComplete.asString() + ClientCommand.SP + "Read Complete" + ClientCommand.CRLF;
                List<String> list = new ArrayList<String>();
                list.add(msg);
                ClientResponse response = new ClientResponse(list);
                ftpClient.notifyListeners(response);
            } catch (Exception e) {
                LOG.error("Error reading server response", e);
            }
        }
public CandleSeries fetchSeries(final String symbol) throws Exception {
        Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
        cal.setTime(begin);
        String beginYear = String.valueOf(cal.get(Calendar.YEAR));
        String beginMonth = String.valueOf(cal.get(Calendar.MONTH));
        String beginDay = String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
        if (end == null) {
            GregorianCalendar gCal = new GregorianCalendar();
            gCal.add(Calendar.DATE, -1);
            end = gCal.getTime();
        }
        cal.setTime(end);
        String day = String.valueOf(cal.get(Calendar.DAY_OF_MONTH));
        String month = String.valueOf(cal.get(Calendar.MONTH));
        String year = String.valueOf(cal.get(Calendar.YEAR));
        String resolution = "d";
        String urlStr = MessageFormat.format(YAHOO_URL, symbol, beginMonth, beginDay, beginYear, month, day, year, resolution);
        BufferedReader reader;
        String line;
        List<String> lineList = new ArrayList<String>();
        log.info("URL [" + urlStr + "]");
        URL url = new URL(urlStr);
        reader = new BufferedReader(new InputStreamReader(url.openStream()));
        line = reader.readLine();
        log.debug(line);
        while ((line = reader.readLine()) != null) {
            lineList.add(0, line);
        }
        List<Candle> candles = new ArrayList<Candle>();
        for (String currentLine : lineList) {
            log.debug(currentLine);
            StringTokenizer str = new StringTokenizer(currentLine, ",");
            String datestring = str.nextToken();
            double open = round(Double.parseDouble(str.nextToken()), 2);
            double high = Double.parseDouble(str.nextToken());
            double low = Double.parseDouble(str.nextToken());
            double close = Double.parseDouble(str.nextToken());
            long volume = 0;
            double adjclose = 0;
            if (str.hasMoreTokens()) {
                volume = Long.parseLong(str.nextToken());
                if (splitAdjust) {
                    adjclose = Double.parseDouble(str.nextToken());
                }
            }
            Date date = sdf.parse(datestring);
            Candle candle = null;
            if (splitAdjust) {
                double adjustmentFactor = adjclose / close;
                candle = new Candle(symbol, date, round(open * adjustmentFactor, 2), round(high * adjustmentFactor, 2), round(low * adjustmentFactor, 2), adjclose, volume);
            } else {
                candle = new Candle(symbol, date, open, high, low, close, volume);
            }
            candles.add(candle);
        }
        return new CandleSeries(candles);
    }
protected void saveResponse(final WebResponse response, final WebRequest request) throws IOException {
        counter_++;
        final String extension = chooseExtension(response.getContentType());
        final File f = createFile(request.getUrl(), extension);
        final InputStream input = response.getContentAsStream();
        final OutputStream output = new FileOutputStream(f);
        try {
            IOUtils.copy(response.getContentAsStream(), output);
        } finally {
            IOUtils.closeQuietly(input);
            IOUtils.closeQuietly(output);
        }
        final URL url = response.getWebRequest().getUrl();
        LOG.info("Created file " + f.getAbsolutePath() + " for response " + counter_ + ": " + url);
        final StringBuilder buffer = new StringBuilder();
        buffer.append("tab[tab.length] = {code: " + response.getStatusCode() + ", ");
        buffer.append("fileName: '" + f.getName() + "', ");
        buffer.append("contentType: '" + response.getContentType() + "', ");
        buffer.append("method: '" + request.getHttpMethod().name() + "', ");
        if (request.getHttpMethod() == HttpMethod.POST && request.getEncodingType() == FormEncodingType.URL_ENCODED) {
            buffer.append("postParameters: " + nameValueListToJsMap(request.getRequestParameters()) + ", ");
        }
        buffer.append("url: '" + escapeJSString(url.toString()) + "', ");
        buffer.append("loadTime: " + response.getLoadTime() + ", ");
        final byte[] bytes = IOUtils.toByteArray(response.getContentAsStream());
        buffer.append("responseSize: " + ((bytes == null) ? 0 : bytes.length) + ", ");
        buffer.append("responseHeaders: " + nameValueListToJsMap(response.getResponseHeaders()));
        buffer.append("};\n");
        appendToJSFile(buffer.toString());
    }
public void copy(File from, String to) throws SystemException {
        assert from != null;
        File dst = new File(folder, to);
        dst.getParentFile().mkdirs();
        FileChannel in = null;
        FileChannel out = null;
        try {
            if (!dst.exists()) dst.createNewFile();
            in = new FileInputStream(from).getChannel();
            out = new FileOutputStream(dst).getChannel();
            in.transferTo(0, in.size(), out);
        } catch (IOException e) {
            throw new SystemException(e);
        } finally {
            try {
                if (in != null) in.close();
            } catch (Exception e1) {
            }
            try {
                if (out != null) out.close();
            } catch (Exception e1) {
            }
        }
    }
public static void copyFile(File in, File out) throws Exception {
        FileChannel sourceChannel = new FileInputStream(in).getChannel();
        FileChannel destinationChannel = new FileOutputStream(out).getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(), destinationChannel);
        sourceChannel.close();
        destinationChannel.close();
    }
private InputStream getConnection(final String url) {
        InputStream is = null;
        try {
            final URLConnection conn = new URL(url).openConnection();
            is = conn.getInputStream();
        } catch (final MalformedURLException e) {
            e.printStackTrace();
        } catch (final IOException e) {
            e.printStackTrace();
        }
        return is;
    }
public static final void copyFile(File source, File destination) throws IOException {
        FileChannel sourceChannel = new FileInputStream(source).getChannel();
        FileChannel targetChannel = new FileOutputStream(destination).getChannel();
        sourceChannel.transferTo(0, sourceChannel.size(), targetChannel);
        sourceChannel.close();
        targetChannel.close();
    }
public boolean copyFile(File source, File dest) {
        try {
            FileReader in = new FileReader(source);
            FileWriter out = new FileWriter(dest);
            int c;
            while ((c = in.read()) != -1) out.write(c);
            in.close();
            out.close();
            return true;
        } catch (Exception e) {
            return false;
        }
    }
public static void main(String[] args) {
        try {
            URL url = new URL("http://localhost:8080/axis/services/Tripcom?wsdl");
            HttpURLConnection connection = (HttpURLConnection) url.openConnection();
            connection.setRequestMethod("POST");
            connection.setDoOutput(true);
            connection.setDoInput(true);
            connection.setRequestProperty("Content-type", "text/xml; charset=utf-8");
            connection.setRequestProperty("SOAPAction", "http://tempuri.org/GetTime");
            String msg = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" + "<soap:Envelope " + " xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">\n" + " <soap:Body>\n" + "   <rdTest xmlns=\"http://tempuri.org/\"> \n" + "   <tns:rdTest message=\"tns:rdTest\"/>  \n" + "   </rdTest>" + " </soap:Body>\n" + "</soap:Envelope>";
            byte[] bytes = msg.getBytes();
            connection.setRequestProperty("Content-length", String.valueOf(bytes.length));
            System.out.println("\nSOAP Aufruf:");
            System.out.println("Content-type:" + connection.getRequestProperty("Content-type"));
            System.out.println("Content-length:" + connection.getRequestProperty("Content-length"));
            System.out.println("SOAPAction:" + connection.getRequestProperty("SOAPAction"));
            System.out.println(msg);
            OutputStream out = connection.getOutputStream();
            out.write(bytes);
            out.close();
            BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
            String inputLine;
            System.out.println("\nServer Antwort:");
            while ((inputLine = in.readLine()) != null) System.out.println(inputLine);
            in.close();
        } catch (Exception e) {
            System.out.println("FEHLER:" + e);
        }
    }
private int[] get51JobId(String address, String category, int pageNum) {
        StringBuffer htmlContent = null;
        try {
            URL url = new URL(ConfigJob51.STR_51JOB_ADVANCE);
            URLConnection connection = url.openConnection();
            connection.setDoOutput(true);
            OutputStream raw = connection.getOutputStream();
            OutputStream buf = new BufferedOutputStream(raw);
            OutputStreamWriter out = new OutputStreamWriter(buf, "gb2312");
            out.write("jobarea=" + address + "&funtype=" + category + "&curr_page=" + pageNum + "");
            out.flush();
            out.close();
            InputStream in = connection.getInputStream();
            in = new BufferedInputStream(in);
            Reader r = new InputStreamReader(in);
            int c;
            htmlContent = new StringBuffer();
            while ((c = r.read()) != -1) {
                htmlContent.append((char) c);
            }
            in.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
        Pattern p = Pattern.compile(JOB51_SEARCHLIST_URL_PATTERN, Pattern.CASE_INSENSITIVE);
        Matcher matcher = p.matcher(htmlContent);
        int idSum = 0;
        int writeToDBSuccessful = 0;
        while (matcher.find()) {
            String s = matcher.group();
            String sql = "insert into `job51`(`id`,`retryCnt`,`Category`) values('" + s.replaceAll("[^0-9]", "") + "','0','" + category + "')";
            if (mysql.executeInsert(sql)) {
                writeToDBSuccessful++;
            }
            idSum++;
        }
        return new int[] { idSum, writeToDBSuccessful };
    }
public static String digest(String str) {
        StringBuffer sb = new StringBuffer();
        try {
            MessageDigest md5 = MessageDigest.getInstance("md5");
            md5.update(str.getBytes("ISO8859-1"));
            byte[] array = md5.digest();
            for (int x = 0; x < 16; x++) {
                if ((array[x] & 0xff) < 0x10) sb.append("0");
                sb.append(Long.toString(array[x] & 0xff, 16));
            }
        } catch (Exception e) {
            System.out.println(e);
        }
        return sb.toString();
    }
private void Submit2URL(URL url) throws Exception {
        HttpURLConnection urlc = null;
        try {
            urlc = (HttpURLConnection) url.openConnection();
            urlc.setRequestMethod("GET");
            urlc.setDoOutput(true);
            urlc.setDoInput(true);
            urlc.setUseCaches(false);
            urlc.setAllowUserInteraction(false);
            if (urlc.getResponseCode() != 200) {
                InputStream in = null;
                Reader reader = null;
                try {
                    in = urlc.getInputStream();
                    reader = new InputStreamReader(in, "UTF-8");
                    int read = 0;
                    char[] buf = new char[1024];
                    String error = null;
                    while ((read = reader.read(buf)) >= 0) {
                        if (error == null) error = new String(buf, 0, read); else error += new String(buf, 0, read);
                    }
                    throw new NpsException(error, ErrorHelper.SYS_UNKOWN);
                } finally {
                    if (reader != null) try {
                        reader.close();
                    } catch (Exception e1) {
                    }
                    if (in != null) try {
                        in.close();
                    } catch (Exception e1) {
                    }
                }
            }
        } finally {
            if (urlc != null) try {
                urlc.disconnect();
            } catch (Exception e1) {
            }
        }
    }
public Epg unmarshallFromUrl(URL url) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
        String tmp = null;
        StringBuilder buffer = new StringBuilder();
        while ((tmp = reader.readLine()) != null) {
            buffer.append(tmp);
        }
        return unmarshall(buffer.toString().getBytes());
    }
public int NthLowestSkill(int n) {
        int[] skillIds = new int[] { 0, 1, 2, 3 };
        for (int j = 0; j < 3; j++) {
            for (int i = 0; i < 3 - j; i++) {
                if (Skills()[skillIds[i]] > Skills()[skillIds[i + 1]]) {
                    int temp = skillIds[i];
                    skillIds[i] = skillIds[i + 1];
                    skillIds[i + 1] = temp;
                }
            }
        }
        return skillIds[n - 1];
    }