semeru/Code-Code-CloneDetection-BigCloneBench huggingface dataset:
public void testJTLM_publish100() 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.DEFAULT_OPTIONS);
        AlignmentType[] alignments = new AlignmentType[] { AlignmentType.bitPacked, AlignmentType.byteAligned, AlignmentType.preCompress, AlignmentType.compress };
        for (AlignmentType alignment : alignments) {
            Transmogrifier encoder = new Transmogrifier();
            EXIDecoder decoder = new EXIDecoder(999);
            Scanner scanner;
            InputSource inputSource;
            encoder.setAlignmentType(alignment);
            decoder.setAlignmentType(alignment);
            encoder.setEXISchema(grammarCache);
            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.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 (n_texts % 100 == 0) {
                        final int n = n_texts / 100;
                        Assert.assertEquals(publish100_centennials[n], exiEvent.getCharacters().makeString());
                    }
                    ++n_texts;
                }
                exiEventList.add(exiEvent);
            }
            Assert.assertEquals(10610, n_events);
        }
    }
public void testDecodeJTLM_publish100() 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.DEFAULT_OPTIONS);
        String[] exiFiles = { "/JTLM/publish100/publish100.bitPacked", "/JTLM/publish100/publish100.byteAligned", "/JTLM/publish100/publish100.preCompress", "/JTLM/publish100/publish100.compress" };
        for (int i = 0; i < Alignments.length; i++) {
            AlignmentType alignment = Alignments[i];
            EXIDecoder decoder = new EXIDecoder();
            Scanner scanner;
            decoder.setAlignmentType(alignment);
            URL url = resolveSystemIdAsURL(exiFiles[i]);
            int n_events, n_texts;
            decoder.setEXISchema(grammarCache);
            decoder.setInputStream(url.openStream());
            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) {
                    String stringValue = exiEvent.getCharacters().makeString();
                    if (stringValue.length() == 0 && exiEvent.getEventType().itemType == EventCode.ITEM_SCHEMA_CH) {
                        --n_events;
                        continue;
                    }
                    if (n_texts % 100 == 0) {
                        final int n = n_texts / 100;
                        Assert.assertEquals(publish100_centennials[n], stringValue);
                    }
                    ++n_texts;
                }
                exiEventList.add(exiEvent);
            }
            Assert.assertEquals(10610, n_events);
        }
    }
public void testDecodeJTLM_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.DEFAULT_OPTIONS);
        String[] exiFiles = { "/JTLM/publish911/publish911.bitPacked", "/JTLM/publish911/publish911.byteAligned", "/JTLM/publish911/publish911.preCompress", "/JTLM/publish911/publish911.compress" };
        for (int i = 0; i < Alignments.length; i++) {
            AlignmentType alignment = Alignments[i];
            EXIDecoder decoder = new EXIDecoder();
            Scanner scanner;
            decoder.setAlignmentType(alignment);
            URL url = resolveSystemIdAsURL(exiFiles[i]);
            int n_events, n_texts;
            decoder.setEXISchema(grammarCache);
            decoder.setInputStream(url.openStream());
            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) {
                    String stringValue = exiEvent.getCharacters().makeString();
                    if (stringValue.length() == 0 && exiEvent.getEventType().itemType == EventCode.ITEM_SCHEMA_CH) {
                        --n_events;
                        continue;
                    }
                    if (n_texts % 100 == 0) {
                        final int n = n_texts / 100;
                        Assert.assertEquals(publish911_centennials[n], stringValue);
                    }
                    ++n_texts;
                }
                exiEventList.add(exiEvent);
            }
            Assert.assertEquals(96576, n_events);
        }
    }
@Override
    protected boolean sendBytes(byte[] data, int offset, int length) {
        try {
            String hex = toHex(data, offset, length);
            URL url = new URL(this.endpoint, "?raw=" + hex);
            System.out.println("Connecting to " + url);
            URLConnection conn = url.openConnection();
            conn.connect();
            Object content = conn.getContent();
            return true;
        } catch (IOException ex) {
            LOGGER.warning(ex.getMessage());
            return false;
        }
    }
@Test
    public void testEncryptDecrypt() throws IOException {
        BlockCipher cipher = new SerpentEngine();
        Random rnd = new Random();
        byte[] key = new byte[256 / 8];
        rnd.nextBytes(key);
        byte[] iv = new byte[cipher.getBlockSize()];
        rnd.nextBytes(iv);
        byte[] data = new byte[1230000];
        new Random().nextBytes(data);
        ByteArrayOutputStream bout = new ByteArrayOutputStream();
        CryptOutputStream eout = new CryptOutputStream(bout, cipher, key);
        eout.write(data);
        eout.close();
        byte[] eData = bout.toByteArray();
        ByteArrayInputStream bin = new ByteArrayInputStream(eData);
        CryptInputStream din = new CryptInputStream(bin, cipher, key);
        bout = new ByteArrayOutputStream();
        IOUtils.copy(din, bout);
        eData = bout.toByteArray();
        Assert.assertTrue(Arrays.areEqual(data, eData));
    }
public void prepareDocumentForEncryption(PDDocument doc) throws CryptographyException, IOException {
        document = doc;
        PDEncryptionDictionary encryptionDictionary = document.getEncryptionDictionary();
        if (encryptionDictionary == null) {
            encryptionDictionary = new PDEncryptionDictionary();
        }
        version = computeVersionNumber();
        revision = computeRevisionNumber();
        encryptionDictionary.setFilter(FILTER);
        encryptionDictionary.setVersion(version);
        encryptionDictionary.setRevision(revision);
        encryptionDictionary.setLength(keyLength);
        String ownerPassword = policy.getOwnerPassword();
        String userPassword = policy.getUserPassword();
        if (ownerPassword == null) {
            ownerPassword = "";
        }
        if (userPassword == null) {
            userPassword = "";
        }
        int permissionInt = policy.getPermissions().getPermissionBytes();
        encryptionDictionary.setPermissions(permissionInt);
        int length = keyLength / 8;
        COSArray idArray = document.getDocument().getDocumentID();
        if (idArray == null || idArray.size() < 2) {
            idArray = new COSArray();
            try {
                MessageDigest md = MessageDigest.getInstance("MD5");
                BigInteger time = BigInteger.valueOf(System.currentTimeMillis());
                md.update(time.toByteArray());
                md.update(ownerPassword.getBytes());
                md.update(userPassword.getBytes());
                md.update(document.getDocument().toString().getBytes());
                byte[] id = md.digest(this.toString().getBytes());
                COSString idString = new COSString();
                idString.append(id);
                idArray.add(idString);
                idArray.add(idString);
                document.getDocument().setDocumentID(idArray);
            } catch (NoSuchAlgorithmException e) {
                throw new CryptographyException(e);
            } catch (IOException e) {
                throw new CryptographyException(e);
            }
        }
        COSString id = (COSString) idArray.getObject(0);
        byte[] o = computeOwnerPassword(ownerPassword.getBytes("ISO-8859-1"), userPassword.getBytes("ISO-8859-1"), revision, length);
        byte[] u = computeUserPassword(userPassword.getBytes("ISO-8859-1"), o, permissionInt, id.getBytes(), revision, length);
        encryptionKey = computeEncryptedKey(userPassword.getBytes("ISO-8859-1"), o, permissionInt, id.getBytes(), revision, length);
        encryptionDictionary.setOwnerKey(o);
        encryptionDictionary.setUserKey(u);
        document.setEncryptionDictionary(encryptionDictionary);
        document.getDocument().setEncryptionDictionary(encryptionDictionary.getCOSDictionary());
    }
public static void main(String[] args) throws Exception {
        System.setProperty("debug", "debug");
        OAuthConsumer consumer = new DefaultOAuthConsumer("YmRF4HDvikvwDxYafsaK", "r)q7L!4X$j$nTS0lXAjC=al9Xf*cLOdyFJsy%2OE");
        consumer.setTokenWithSecret("5722da60fee79ef9efc2d383f871d550", "39142f31ad8a7e6ff7b87f36cc9e8f10");
        URL url = new URL("http://api.t.sohu.com/statuses/update.json");
        HttpURLConnection request = (HttpURLConnection) url.openConnection();
        request.setDoOutput(true);
        request.setRequestMethod("POST");
        HttpParameters para = new HttpParameters();
        para.put("status", URLEncoder.encode("中 文", "utf-8").replaceAll("\\+", "%20"));
        consumer.setAdditionalParameters(para);
        consumer.sign(request);
        OutputStream ot = request.getOutputStream();
        ot.write(("status=" + URLEncoder.encode("1中 文", "utf-8")).replaceAll("\\+", "%20").getBytes());
        ot.flush();
        ot.close();
        System.out.println("Sending request...");
        request.connect();
        System.out.println("Response: " + request.getResponseCode() + " " + request.getResponseMessage());
        BufferedReader reader = new BufferedReader(new InputStreamReader(request.getInputStream()));
        String b = null;
        while ((b = reader.readLine()) != null) {
            System.out.println(b);
        }
    }
@RequestMapping("/import")
    public String importPicture(@ModelAttribute PictureImportCommand command) throws IOException {
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        URL url = command.getUrl();
        IOUtils.copy(url.openStream(), baos);
        byte[] imageData = imageFilterService.touchupImage(baos.toByteArray());
        String filename = StringUtils.substringAfterLast(url.getPath(), "/");
        String email = userService.getCurrentUser().getEmail();
        Picture picture = new Picture(email, filename, command.getDescription(), imageData);
        pictureRepository.store(picture);
        return "redirect:/picture/gallery";
    }
@Override
    public void action(String msg, String uri, Gateway gateway) throws Exception {
        String city = "成都";
        if (msg.indexOf("#") != -1) {
            city = msg.substring(msg.indexOf("#") + 1);
        }
        String url = "http://webservice.webxml.com.cn/WebServices/WeatherWS.asmx/getWeather?theCityCode={city}&theUserID=";
        url = url.replace("{city}", URLEncoder.encode(city, "UTF8"));
        HttpURLConnection conn = (HttpURLConnection) new URL(url).openConnection();
        if (conn.getResponseCode() == 200) {
            SAXBuilder builder = new SAXBuilder();
            Document doc = builder.build(conn.getInputStream());
            List strings = doc.getRootElement().getChildren();
            String[] sugguestions = getText(strings.get(6)).split("\n");
            StringBuffer buffer = new StringBuffer();
            buffer.append("欢迎使用MapleSMS的天气服务！\n");
            buffer.append("你查询的是 " + getText(strings.get(1)) + "的天气。\n");
            buffer.append(getText(strings.get(4)) + "。\n");
            buffer.append(getText(strings.get(5)) + "。\n");
            buffer.append(sugguestions[0] + "\n");
            buffer.append(sugguestions[1] + "\n");
            buffer.append(sugguestions[7] + "\n");
            buffer.append("感谢你使用MapleSMS的天气服务！祝你愉快！");
            gateway.sendSMS(uri, buffer.toString());
        } else {
            gateway.sendSMS(uri, "对不起，你输入的城市格式有误，请检查后再试~");
        }
    }
public static final String encryptPassword(String loginName, String password) {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(loginName.toUpperCase().getBytes("UTF-8"));
            md5.update(password.getBytes("UTF-8"));
            byte[] ba = md5.digest();
            return byte2hex(ba);
        } catch (Exception e) {
            return password;
        }
    }
@Override
    public Response callService(RemoteCallUrl urlModel) throws RemoteCallFailedException {
        String path;
        if (urlModel.getRootPath() != null) path = urlModel.getRootPath() + urlModel.getServicePath(); else path = urlModel.getServicePath();
        try {
            URL url = new URL(HTTP_PROTOCOL, urlModel.getHost(), urlModel.getPort(), path);
            URLConnection urlConnection = url.openConnection();
            BufferedReader in = new BufferedReader(new InputStreamReader(url.openStream()));
            String inputLine;
            String data = "";
            while ((inputLine = in.readLine()) != null) data += inputLine;
            Response remoteData = new Response(new String(data));
            remoteData.setStatus(urlConnection.getHeaderField(Response.RPC_STATUS_NAME));
            in.close();
            return remoteData;
        } catch (MalformedURLException e) {
            logger.error("Illegal URL. Cannot connect to this remote object", e);
            throw new RemoteCallFailedException("Illegal URL:" + e.getMessage(), e);
        } catch (IOException e) {
            logger.error("Cannot read from source. Please check remote object address", e);
            throw new RemoteCallFailedException("Fatal transport error:" + e.getMessage(), e);
        }
    }
@Test
    public void shouldProgateStagingRepoToYumGroupRepo() throws Exception {
        givenGroupRepository(GROUP_REPO_ID, "maven2yum");
        givenClosedStagingRepoWithRpm(ARTIFACT_ID_1, "4.3.2");
        givenClosedStagingRepoWithRpm(ARTIFACT_ID_2, "2.3.4");
        wait(10, SECONDS);
        final HttpResponse response = executeGetWithResponse(NEXUS_BASE_URL + "/content/groups/staging-test-group/repodata/primary.xml.gz");
        final String repoContent = IOUtils.toString(new GZIPInputStream(new ByteArrayInputStream(toByteArray(response.getEntity()))));
        assertThat(response.getStatusLine().getStatusCode(), is(200));
        assertThat(repoContent, containsString(ARTIFACT_ID_1));
        assertThat(repoContent, containsString(ARTIFACT_ID_2));
    }
public void testBasic() {
        CameraInfo ci = C328rCameraInfo.getInstance();
        assertNotNull(ci);
        assertNotNull(ci.getCapabilities());
        assertFalse(ci.getCapabilities().isEmpty());
        System.out.println(ci.getUrl());
        URL url = ci.getUrl();
        try {
            URLConnection conn = url.openConnection();
            conn.connect();
            InputStream is = conn.getInputStream();
            InputStreamReader isr = new InputStreamReader(is);
            BufferedReader br = new BufferedReader(isr);
            String line = null;
            while ((line = br.readLine()) != null) {
                System.out.println(line);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
public static String md5Hash(String inString) throws TopicSpacesException {
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            md5.update(inString.getBytes());
            byte[] array = md5.digest();
            StringBuffer buf = new StringBuffer();
            int len = array.length;
            for (int i = 0; i < len; i++) {
                int b = array[i] & 0xFF;
                buf.append(Integer.toHexString(b));
            }
            return buf.toString();
        } catch (Exception x) {
            throw new TopicSpacesException(x);
        }
    }
@Override
    public void send(String payload, TransportReceiver receiver) {
        HttpURLConnection connection = null;
        try {
            connection = (HttpURLConnection) url.openConnection();
            configureConnection(connection);
            OutputStream out = connection.getOutputStream();
            out.write(payload.getBytes("UTF-8"));
            out.close();
            int status = connection.getResponseCode();
            if (status != HttpURLConnection.HTTP_OK) {
                ServerFailure failure = new ServerFailure(status + " " + connection.getResponseMessage());
                receiver.onTransportFailure(failure);
                return;
            }
            List<String> cookieHeaders = connection.getHeaderFields().get("Set-Cookie");
            if (cookieHeaders != null) {
                for (String header : cookieHeaders) {
                    try {
                        JSONObject cookie = Cookie.toJSONObject(header);
                        String name = cookie.getString("name");
                        String value = cookie.getString("value");
                        String domain = cookie.optString("Domain");
                        if (domain == null || url.getHost().endsWith(domain)) {
                            String path = cookie.optString("Path");
                            if (path == null || url.getPath().startsWith(path)) {
                                cookies.put(name, value);
                            }
                        }
                    } catch (JSONException ignored) {
                    }
                }
            }
            String encoding = connection.getContentEncoding();
            InputStream in = connection.getInputStream();
            if ("gzip".equalsIgnoreCase(encoding)) {
                in = new GZIPInputStream(in);
            } else if ("deflate".equalsIgnoreCase(encoding)) {
                in = new InflaterInputStream(in);
            } else if (encoding != null) {
                receiver.onTransportFailure(new ServerFailure("Unknown server encoding " + encoding));
                return;
            }
            ByteArrayOutputStream bytes = new ByteArrayOutputStream();
            byte[] buffer = new byte[4096];
            int read = in.read(buffer);
            while (read != -1) {
                bytes.write(buffer, 0, read);
                read = in.read(buffer);
            }
            in.close();
            String received = new String(bytes.toByteArray(), "UTF-8");
            receiver.onTransportSuccess(received);
        } catch (IOException e) {
            ServerFailure failure = new ServerFailure(e.getMessage(), e.getClass().getName(), null, true);
            receiver.onTransportFailure(failure);
        } finally {
            if (connection != null) {
                connection.disconnect();
            }
        }
    }
public static void copyFile(final FileInputStream in, final File out) throws IOException {
        final FileChannel inChannel = in.getChannel();
        final FileChannel outChannel = new FileOutputStream(out).getChannel();
        try {
            inChannel.transferTo(0, inChannel.size(), outChannel);
        } catch (final IOException e) {
            throw e;
        } finally {
            if (inChannel != null) inChannel.close();
            if (outChannel != null) outChannel.close();
        }
    }
public Object execute(Connection connection) throws JAXRException {
                    RegistryObject registryObject = connection.getRegistryService().getBusinessQueryManager().getRegistryObject(id);
                    if (registryObject instanceof ExtrinsicObject) {
                        ExtrinsicObject extrinsicObject = (ExtrinsicObject) registryObject;
                        DataHandler dataHandler = extrinsicObject.getRepositoryItem();
                        if (dataHandler != null) {
                            response.setContentType("text/html");
                            try {
                                PrintWriter out = response.getWriter();
                                InputStream is = dataHandler.getInputStream();
                                try {
                                    final XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(out);
                                    xmlStreamWriter.writeStartDocument();
                                    xmlStreamWriter.writeStartElement("div");
                                    xmlStreamWriter.writeStartElement("textarea");
                                    xmlStreamWriter.writeAttribute("name", "repositoryItem");
                                    xmlStreamWriter.writeAttribute("class", "xml");
                                    xmlStreamWriter.writeAttribute("style", "display:none");
                                    IOUtils.copy(new XmlInputStreamReader(is), new XmlStreamTextWriter(xmlStreamWriter));
                                    xmlStreamWriter.writeEndElement();
                                    xmlStreamWriter.writeStartElement("script");
                                    xmlStreamWriter.writeAttribute("class", "javascript");
                                    xmlStreamWriter.writeCharacters("dp.SyntaxHighlighter.HighlightAll('repositoryItem');");
                                    xmlStreamWriter.writeEndElement();
                                    xmlStreamWriter.writeEndElement();
                                    xmlStreamWriter.writeEndDocument();
                                    xmlStreamWriter.flush();
                                } finally {
                                    is.close();
                                }
                            } catch (Throwable ex) {
                                log.error("Error while trying to format repository item " + id, ex);
                            }
                        } else {
                        }
                    } else {
                    }
                    return null;
                }