本文整理汇总了Java中java.io.DataOutputStream.writeBytes方法的典型用法代码示例。如果您正苦于以下问题:Java DataOutputStream.writeBytes方法的具体用法?Java DataOutputStream.writeBytes怎么用?Java DataOutputStream.writeBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.io.DataOutputStream
的用法示例。
在下文中一共展示了DataOutputStream.writeBytes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: login
import java.io.DataOutputStream; //导入方法依赖的package包/类
public String login(String username, String password) throws MalformedURLException, IOException {
URL url = new URL("https://authserver.mojang.com/authenticate"); //Mojang正版验证服务器
HttpURLConnection conn = (HttpURLConnection) url.openConnection(); //创建连接
/**
* 连接参数设置
*/
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setRequestMethod("POST");
conn.setUseCaches(false);
conn.setInstanceFollowRedirects(true);
conn.setConnectTimeout(20000);
conn.setReadTimeout(300000);
conn.setRequestProperty("Content-Type", "application/json");
conn.connect(); //连接服务器
DataOutputStream out = new DataOutputStream(conn.getOutputStream()); //创建标准输出系统
String json = "{\"agent\": {\"name\": \"Minecraft\",\"version\": 1},\"username\": \"" + username
+ "\",\"password\": \"" + password + "\"}"; //需要发送的信息
out.writeBytes(json); //发送信息
if (conn.getResponseCode() == 403) { //如果服务器返回403错误
return "403"; //返回403
}
DataInputStream in = new DataInputStream(conn.getInputStream()); //如果正常
return in.readLine(); //返回服务器结果
}
示例2: write
import java.io.DataOutputStream; //导入方法依赖的package包/类
void write(DataOutputStream os) throws IOException {
Iterator<Map.Entry<Object, Object>> it = entrySet().iterator();
while (it.hasNext()) {
Map.Entry<Object, Object> e = it.next();
StringBuffer buffer = new StringBuffer(
((Name)e.getKey()).toString());
buffer.append(": ");
String value = (String)e.getValue();
if (value != null) {
byte[] vb = value.getBytes("UTF8");
value = new String(vb, 0, 0, vb.length);
}
buffer.append(value);
buffer.append("\r\n");
Manifest.make72Safe(buffer);
os.writeBytes(buffer.toString());
}
os.writeBytes("\r\n");
}
示例3: rootcheck
import java.io.DataOutputStream; //导入方法依赖的package包/类
public static void rootcheck(){
String result = "";
try {
pros = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(pros.getOutputStream());
BufferedReader bf = new BufferedReader(new InputStreamReader(pros.getInputStream()));
os.writeBytes("id -u\n");
os.flush();
result = bf.readLine();
if(result == null)
result = "-1";
if (result.equals("0"))
isrooted = true;
else
isrooted = false;
} catch (IOException e) {
isrooted = false;
e.printStackTrace();
}
rootchecked = true;
}
示例4: createInputOutPutFolder
import java.io.DataOutputStream; //导入方法依赖的package包/类
static void createInputOutPutFolder(Path inDir, Path outDir, int numMaps)
throws Exception {
FileSystem fs = FileSystem.get(conf);
if (fs.exists(outDir)) {
fs.delete(outDir, true);
}
if (!fs.exists(inDir)) {
fs.mkdirs(inDir);
}
String input = "The quick brown fox\n" + "has many silly\n"
+ "red fox sox\n";
for (int i = 0; i < numMaps; ++i) {
DataOutputStream file = fs.create(new Path(inDir, "part-" + i));
file.writeBytes(input);
file.close();
}
}
示例5: getByte
import java.io.DataOutputStream; //导入方法依赖的package包/类
/**
* 通用方法,将数据转换为小端整数格式
* @param data
* @return
*/
private static byte[] getByte(String data){
ByteArrayOutputStream boutput = new ByteArrayOutputStream();
DataOutputStream doutput = new DataOutputStream(boutput);
try
{
boutput.reset();
doutput.write(FormatTransfer.toLH(data.length() + 8), 0, 4); // 4 bytes packet length
doutput.write(FormatTransfer.toLH(data.length() + 8), 0, 4); // 4 bytes packet length
doutput.write(FormatTransfer.toLH(DY_MESSAGE_TYPE_CLIENT), 0, 2); // 2 bytes message type
doutput.writeByte(0); // 1 bytes encrypt
doutput.writeByte(0); // 1 bytes reserve
doutput.writeBytes(data);
}
catch(Exception e)
{
e.printStackTrace();
}
return boutput.toByteArray();
}
示例6: executeRootCommand
import java.io.DataOutputStream; //导入方法依赖的package包/类
public static void executeRootCommand(String... command) {
if (shell == null) {
KRFAM.log("No Shell");
} else {
try {
Process p = shell;
DataOutputStream o = new DataOutputStream(p.getOutputStream());
for (String c : command) {
o.writeBytes(c + "\n");
}
o.flush();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
示例7: execRootCmdSilent
import java.io.DataOutputStream; //导入方法依赖的package包/类
protected static int execRootCmdSilent(String paramString) {
try {
Process localProcess = Runtime.getRuntime().exec("su");
Object localObject = localProcess.getOutputStream();
DataOutputStream localDataOutputStream = new DataOutputStream(
(OutputStream) localObject);
String str = String.valueOf(paramString);
localObject = str + "\n";
localDataOutputStream.writeBytes((String) localObject);
localDataOutputStream.flush();
localDataOutputStream.writeBytes("exit\n");
localDataOutputStream.flush();
localProcess.waitFor();
int result = localProcess.exitValue();
return result;
} catch (Exception localException) {
localException.printStackTrace();
return -1;
}
}
示例8: verify
import java.io.DataOutputStream; //导入方法依赖的package包/类
public boolean verify(final String captchaResponse) {
boolean result = false;
try {
final URL uri = new URL(Constants.GOOGLE_URL);
final HttpsURLConnection con = (HttpsURLConnection) uri.openConnection();
con.setRequestMethod(Constants.POST_METHOD);
con.setRequestProperty("User-Agent", Constants.USER_AGENT);
con.setRequestProperty("Accept-Language", Constants.ACCEPT_LANGUAGE);
con.setDoOutput(true);
final DataOutputStream os = new DataOutputStream(con.getOutputStream());
os.writeBytes(urlParams(captchaResponse));
os.flush();
os.close();
final int responseCode = con.getResponseCode();
if(responseCode == 200){
final BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
final JSONObject responseObj = new JSONObject(response.toString());
if(responseObj.getBoolean("success")){
result = true;
}
}
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
示例9: runJob
import java.io.DataOutputStream; //导入方法依赖的package包/类
static boolean runJob(JobConf conf, Path inDir, Path outDir, int numMaps,
int numReds) throws IOException, InterruptedException {
FileSystem fs = FileSystem.get(conf);
if (fs.exists(outDir)) {
fs.delete(outDir, true);
}
if (!fs.exists(inDir)) {
fs.mkdirs(inDir);
}
String input = "The quick brown fox\n" + "has many silly\n"
+ "red fox sox\n";
for (int i = 0; i < numMaps; ++i) {
DataOutputStream file = fs.create(new Path(inDir, "part-" + i));
file.writeBytes(input);
file.close();
}
DistributedCache.addFileToClassPath(TestMRJobs.APP_JAR, conf, fs);
conf.setOutputCommitter(CustomOutputCommitter.class);
conf.setInputFormat(TextInputFormat.class);
conf.setOutputKeyClass(LongWritable.class);
conf.setOutputValueClass(Text.class);
FileInputFormat.setInputPaths(conf, inDir);
FileOutputFormat.setOutputPath(conf, outDir);
conf.setNumMapTasks(numMaps);
conf.setNumReduceTasks(numReds);
JobClient jobClient = new JobClient(conf);
RunningJob job = jobClient.submitJob(conf);
return jobClient.monitorAndPrintJob(conf, job);
}
示例10: request
import java.io.DataOutputStream; //导入方法依赖的package包/类
public static String request(String target, Map<String, String> parameters, Map<String, String> headers, String body, String method) throws IOException {
URL targetUrl = new URL(target + createParameterString(parameters));
HttpURLConnection connection = (HttpURLConnection) targetUrl.openConnection();
if(headers != null && !headers.isEmpty()){
headers.forEach(connection::setRequestProperty);
}
connection.setRequestMethod(method.toUpperCase());
connection.setConnectTimeout(15000);
connection.setReadTimeout(15000);
if(body != null && !body.equals("")) {
connection.setDoOutput(true);
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.writeBytes(body);
outputStream.flush();
outputStream.close();
}
BufferedReader inputStream = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
StringBuilder response = new StringBuilder();
while ((inputLine = inputStream.readLine()) != null) {
response.append(inputLine).append("\n");
}
inputStream.close();
connection.disconnect();
return response.toString();
}
示例11: closeRuntime
import java.io.DataOutputStream; //导入方法依赖的package包/类
static void closeRuntime(Process p, DataOutputStream o) {
try {
if (o != null) {
o.writeBytes("exit\n");
o.close();
}
p.destroy();
} catch (Exception e) {
e.printStackTrace();
}
}
示例12: sendParcel
import java.io.DataOutputStream; //导入方法依赖的package包/类
protected Thread sendParcel(ParcelContainer container, int code, int flags) throws IOException {
//Prevent from casting exceptions with respect to "Network Access on Main Thread"
StrictMode.setThreadPolicy(new StrictMode.ThreadPolicy.Builder().permitAll().build());
String resource = "/parcel/" + container.getParcelID();
URL url = ConnectionUtils.getBadIntentURL(resource, sPrefs, port);
String jsonData = SerializationUtils.getJson(container, code, flags);
final HttpURLConnection conn = ConnectionUtils.getBadIntentHttpURLConnection(url, sPrefs);
conn.setRequestMethod("POST");
conn.setRequestProperty("__BadIntent__", "Parcel");
conn.setRequestProperty("__BadIntent__.package", lpparam.packageName);
conn.setRequestProperty("Content-Type", "application/json; charset=UTF-8");
conn.setRequestProperty("Accept", "application/json");
conn.setDoOutput(true);
conn.connect();
DataOutputStream writer = new DataOutputStream(conn.getOutputStream());
writer.writeBytes(jsonData);
writer.flush();
writer.close();
//create new thread, which reads HTTP result
return ConnectionUtils.readResponseAndCloseConnection(conn);
}
示例13: executePostRequest
import java.io.DataOutputStream; //导入方法依赖的package包/类
public static String executePostRequest(String targetURL, String parameterString) throws Exception {
// create connection
URL url = new URL(targetURL);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/json");
// write parameter string
DataOutputStream outputStream = new DataOutputStream(connection.getOutputStream());
outputStream.writeBytes(parameterString);
outputStream.flush();
outputStream.close();
// get response
BufferedReader reader = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String line;
StringBuilder response = new StringBuilder();
while ((line = reader.readLine()) != null) {
response.append(line);
}
reader.close();
return response.toString();
}
示例14: canRunRootCommands
import java.io.DataOutputStream; //导入方法依赖的package包/类
public static boolean canRunRootCommands()
{
boolean retval = false;
Process suProcess;
try
{
suProcess = Runtime.getRuntime().exec("su");
DataOutputStream os = new DataOutputStream(suProcess.getOutputStream());
DataInputStream osRes = new DataInputStream(suProcess.getInputStream());
if (null != os && null != osRes)
{
// Getting the id of the current user to check if this is root
os.writeBytes("id\n");
os.flush();
String currUid = osRes.readLine();
Log.d("Receive", currUid);
boolean exitSu = false;
if (null == currUid)
{
retval = false;
exitSu = false;
Log.d("ROOT", "Can't get root access or denied by user");
}
else if (true == currUid.contains("uid=0"))
{
retval = true;
exitSu = true;
Log.d("ROOT", "Root access granted");
}
else
{
retval = false;
exitSu = true;
Log.d("ROOT", "Root access rejected: " + currUid);
}
if (exitSu)
{
os.writeBytes("exit\n");
os.flush();
}
}
}
catch (Exception e)
{
// Can't get root !
// Probably broken pipe exception on trying to write to output stream (os) after su failed, meaning that the device is not rooted
retval = false;
Log.d("ROOT", "Root access rejected [" + e.getClass().getName() + "] : " + e.getMessage());
}
return retval;
}
示例15: validateCustomer
import java.io.DataOutputStream; //导入方法依赖的package包/类
private boolean validateCustomer(String login, String password) {
if (customerServiceLocation == null || customerServiceLocation == "") {
customerServiceLocation = "localhost/acmeair";
}
/*Form form = new Form();
form.param("login", login);
form.param("password", password);
ClientBuilder cb = ClientBuilder.newBuilder();
Client c = cb.build();
WebTarget t = c.target("http://"+ customerServiceLocation + VALIDATE_PATH);
Builder builder = t.request();
builder.accept(MediaType.TEXT_PLAIN);
Response res = builder.post(Entity.entity(form,MediaType.APPLICATION_FORM_URLENCODED_TYPE), Response.class);
String output = res.readEntity(String.class);
c.close();
*/
try {
// Set maxConnections - this seems to help with keepalives/running out of sockets with a high load.
if (System.getProperty("http.maxConnections")==null) {
System.setProperty("http.maxConnections", "50");
}
String url = "http://"+ customerServiceLocation + VALIDATE_PATH;
URL obj = new URL(url);
HttpURLConnection conn = (HttpURLConnection) obj.openConnection();
// add request header
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
String urlParameters="login="+login+"&password="+password;
// Send post request
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String inputLine;
StringBuffer response = new StringBuffer();
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
conn.disconnect(); // Is this necessary?
// print result
String output=response.toString();
JSONObject jsonObject = (JSONObject)JSONValue.parse(output);
String validCustomer =(String) jsonObject.get("validCustomer");
if(validCustomer.equals("true")) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
return false;
}