Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
00a44a1d
Commit
00a44a1d
authored
Mar 25, 2020
by
Him188
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix build
parent
64e36ea7
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
81 deletions
+71
-81
.gitignore
.gitignore
+2
-0
buildSrc/src/main/kotlin/GitToken.kt
buildSrc/src/main/kotlin/GitToken.kt
+0
-8
buildSrc/src/main/kotlin/GitUploader.java
buildSrc/src/main/kotlin/GitUploader.java
+0
-73
buildSrc/src/main/kotlin/upload/GitToken.kt
buildSrc/src/main/kotlin/upload/GitToken.kt
+69
-0
No files found.
.gitignore
View file @
00a44a1d
...
@@ -42,3 +42,5 @@ local.properties
...
@@ -42,3 +42,5 @@ local.properties
# Maven publishing credits
# Maven publishing credits
keys.properties
keys.properties
/plugins/
/plugins/
token.txt
\ No newline at end of file
buildSrc/src/main/kotlin/GitToken.kt
deleted
100644 → 0
View file @
64e36ea7
fun
getGitToken
():
String
{
with
(
System
.
getProperty
(
"user.dir"
)
+
"/token.txt"
){
println
(
"reading token file in "
+
this
)
return
File
(
this
).
readText
()
}
}
\ No newline at end of file
buildSrc/src/main/kotlin/GitUploader.java
deleted
100644 → 0
View file @
64e36ea7
import
java.io.*
;
import
java.net.HttpURLConnection
;
import
java.net.URL
;
import
java.util.Base64
;
public
class
GitUploader
{
public
static
boolean
create
(
String
url
,
File
file
)
{
long
begin
=
System
.
currentTimeMillis
();
System
.
out
.
println
(
"上传开始..."
);
//StringBuffer result = new StringBuffer();
BufferedReader
in
=
null
;
HttpURLConnection
conn
=
null
;
try
{
URL
realUrl
=
new
URL
(
url
);
conn
=
(
HttpURLConnection
)
realUrl
.
openConnection
();
conn
.
setConnectTimeout
(
120000
);
conn
.
setReadTimeout
(
120000
);
// 设置
conn
.
setDoOutput
(
true
);
// 需要输出
conn
.
setDoInput
(
true
);
// 需要输入
conn
.
setUseCaches
(
false
);
// 不允许缓存
conn
.
setRequestMethod
(
"PUT"
);
// 设置PUT方式连接
conn
.
setRequestProperty
(
"Content-Type"
,
"application/json"
);
conn
.
setRequestProperty
(
"Authorization"
,
"token "
+
getGitToken
());
conn
.
setRequestProperty
(
"User-Agent"
,
"Github File Uploader App"
);
conn
.
connect
();
// 传输数据
DataOutputStream
dos
=
new
DataOutputStream
(
conn
.
getOutputStream
());
// 传输json头部
dos
.
writeBytes
(
"{\"message\":\".\",\"content\":\""
);
// 传输文件内容
byte
[]
buffer
=
new
byte
[
1024
*
1002
];
// 3的倍数
RandomAccessFile
raf
=
new
RandomAccessFile
(
file
,
"r"
);
long
size
=
raf
.
read
(
buffer
);
while
(
size
>
-
1
)
{
if
(
size
==
buffer
.
length
)
{
dos
.
write
(
Base64
.
getEncoder
().
encode
(
buffer
));
}
else
{
byte
tmp
[]
=
new
byte
[(
int
)
size
];
System
.
arraycopy
(
buffer
,
0
,
tmp
,
0
,
(
int
)
size
);
dos
.
write
(
Base64
.
getEncoder
().
encode
(
tmp
));
}
size
=
raf
.
read
(
buffer
);
}
raf
.
close
();
// 传输json尾部
dos
.
writeBytes
(
"\"}"
);
dos
.
flush
();
dos
.
close
();
in
=
new
BufferedReader
(
new
InputStreamReader
(
conn
.
getInputStream
()));
String
line
;
while
((
line
=
in
.
readLine
())
!=
null
)
{
//result.append(line).append("\n");
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"发送PUT请求出现异常!"
);
e
.
printStackTrace
();
return
false
;
}
finally
{
try
{
in
.
close
();
}
catch
(
Exception
e2
)
{
}
}
long
end
=
System
.
currentTimeMillis
();
System
.
out
.
printf
(
"上传结束,耗时 %ds\n"
,
(
end
-
begin
)
/
1000
);
//result.toString()
return
true
;
}
}
buildSrc/src/main/kotlin/upload/GitToken.kt
0 → 100644
View file @
00a44a1d
package
upload
import
java.io.*
import
java.net.HttpURLConnection
import
java.net.URL
import
java.util.*
object
GitToken
{
private
fun
getGitToken
():
String
{
with
(
System
.
getProperty
(
"user.dir"
)
+
"/token.txt"
)
{
println
(
"reading token file in $this"
)
return
File
(
this
).
readText
()
}
}
fun
upload
(
file
:
File
,
url
:
String
)
{
val
begin
=
System
.
currentTimeMillis
()
println
(
"上传开始..."
)
//StringBuffer result = new StringBuffer();
//StringBuffer result = new StringBuffer();
var
`in`
:
BufferedReader
?
=
null
var
conn
:
HttpURLConnection
?
=
null
conn
=
URL
(
url
).
openConnection
()
as
HttpURLConnection
conn
.
connectTimeout
=
120000
conn
.
readTimeout
=
120000
// 设置
conn
.
doOutput
=
true
// 需要输出
conn
.
doInput
=
true
// 需要输入
conn
.
useCaches
=
false
// 不允许缓存
conn
.
requestMethod
=
"PUT"
// 设置PUT方式连接
conn
.
setRequestProperty
(
"Content-Type"
,
"application/json"
)
conn
.
setRequestProperty
(
"Authorization"
,
"token "
+
getGitToken
())
conn
.
setRequestProperty
(
"User-Agent"
,
"Github File Uploader App"
)
conn
.
connect
()
// 传输数据
val
dos
=
DataOutputStream
(
conn
.
outputStream
)
// 传输json头部
dos
.
writeBytes
(
"{\"message\":\".\",\"content\":\""
)
// 传输文件内容
val
buffer
=
ByteArray
(
1024
*
1002
)
// 3的倍数
val
raf
=
RandomAccessFile
(
file
,
"r"
)
var
size
:
Long
=
raf
.
read
(
buffer
).
toLong
()
while
(
size
>
-
1
)
{
if
(
size
==
buffer
.
size
.
toLong
())
{
dos
.
write
(
Base64
.
getEncoder
().
encode
(
buffer
))
}
else
{
val
tmp
=
ByteArray
(
size
.
toInt
())
System
.
arraycopy
(
buffer
,
0
,
tmp
,
0
,
size
.
toInt
())
dos
.
write
(
Base64
.
getEncoder
().
encode
(
tmp
))
}
size
=
raf
.
read
(
buffer
).
toLong
()
}
raf
.
close
()
// 传输json尾部
dos
.
writeBytes
(
"\"}"
)
dos
.
flush
()
dos
.
close
()
`in`
=
BufferedReader
(
InputStreamReader
(
conn
.
inputStream
))
var
line
:
String
?
while
(
`in`
.
readLine
().
also
{
line
=
it
}
!=
null
)
{
//result.append(line).append("\n");
}
val
end
=
System
.
currentTimeMillis
()
System
.
out
.
printf
(
"Upload finished within %d seconds\n"
,
(
end
-
begin
)
/
1000
)
//result.toString()
//result.toString()
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment