我正在使用 Kotlin Android 应用程序访问 API 端点。在此 API 调用中,我返回一个字节数组。我想看到的是一种将字节数组转换为 pdf 文件并将其保存在手机下载文件夹中的方法。
private suspend fun getIDCard(sessionID: String?, carriermemid: String?): ByteArray? {
var results: String = ""
val postData = "{\"sessionid\": \" $sessionID\"}"
val outputStreamWriter: OutputStreamWriter
var byteArray: ByteArray? = null
val url: URL = URL(idURL + carriermemid)
val conn: HttpURLConnection = url.openConnection() as HttpURLConnection
try {
conn.setRequestProperty(apiConfig.typeKey, apiConfig.typeValueJSON)
conn.setRequestProperty("Accept", "application/json")
conn.setRequestProperty("sessionid", sessionID)
conn.requestMethod = apiConfig.methodGet
val responseCode: Int = conn.responseCode
println("Response Code :: $responseCode")
//returning 404
return if (responseCode == HttpURLConnection.HTTP_OK) {// …Run Code Online (Sandbox Code Playgroud) 我当然有一些代码将.doc文档转换为html,但我用来将.docx转换为文本的代码却不能得到文本并将其转换.以下是我的代码.
private void convertWordDocXtoHTML(File file) throws ParserConfigurationException, TransformerConfigurationException, TransformerException, IOException {
XWPFDocument wordDocument = null;
try {
wordDocument = new XWPFDocument(new FileInputStream(file));
} catch (IOException ex) {
Exceptions.printStackTrace(ex);
}
WordToHtmlConverter wordToHtmlConverter = new WordToHtmlConverter(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument());
org.w3c.dom.Document htmlDocument = wordToHtmlConverter.getDocument();
ByteArrayOutputStream out = new ByteArrayOutputStream();
DOMSource domSource = new DOMSource(htmlDocument);
StreamResult streamResult = new StreamResult(out);
TransformerFactory tf = TransformerFactory.newInstance();
Transformer serializer = tf.newTransformer();
serializer.setOutputProperty(OutputKeys.ENCODING, "UTF-8");
serializer.setOutputProperty(OutputKeys.INDENT, "yes");
serializer.setOutputProperty(OutputKeys.METHOD, "html");
serializer.transform(domSource, streamResult);
out.close();
String result = new String(out.toByteArray());
acDocTextArea.setText(newDocText);
String htmlText = result; …Run Code Online (Sandbox Code Playgroud) 我使用docx4j来读取和解析.docx文件,但是当我遍历段落时,它会在一次传递中读取而不是所有段落.下面是我正在使用的代码示例.
private void replaceAcrAndDef(String acrName, String acrParensName, String oldDef, String newDef){
String XPATH_TO_SELECT_TEXT_NODES = "//w:t";
List<Object> paragraphs = template.getMainDocumentPart().getJAXBNodesViaXPath(XPATH_TO_SELECT_TEXT_NODES, true);
for (Object obj : paragraphs){
Text text = (Text) ((JAXBElement)obj).getValue();
String textValue = text.getValue();
System.out.println(textValue);
}
Run Code Online (Sandbox Code Playgroud)
在上面的for循环的一次传递期间,这将作为第一段读取 -
"团队通过为任务,测试和管理以及一般服务网络和系统提供直接的MDA经验,对这些要求有深刻的理解.通过对任务,流程和优先级的既定理解,培养低风险,反应灵敏的团队的好处.使用基于综合的"
但它缺少该段的最后部分.这将在连续的传球中出现.我在这做错了什么.
该段的全部内容如下:
团队通过为任务,测试和管理以及一般服务网络和系统提供直接的MDA经验,对需求有深刻的理解.低风险,反应迅速的团队的好处是对任务,流程和优先事项有着深刻的理解.我们使用基于角色的综合信息技术(RBA)方法与合作承包商,现有流程和补充流程的增加协同工作.
我不知道是否有办法获得整个段落,但是如果有的话会很好,因为我需要逐段更换字符串.
我有一个活动,显示使用谷歌地图的Android应用程序的地图,我想用我创建的ping图像替换我正在使用的黄色标记,名为fillingstation.png.我将如何做到这一点,因为我对Android App Development还不熟悉.
MapViewActivity.java
private void showFuelStops(String location) throws IOException{
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses;
addresses = geocoder.getFromLocationName(location, 1);
if(addresses.size() > 0) {
BitmapDescriptor subwayBitmapDescriptor = BitmapDescriptorFactory.defaultMarker(BitmapDescriptorFactory.HUE_YELLOW);
double latitude= addresses.get(0).getLatitude();
double longitude= addresses.get(0).getLongitude();
LatLng subLoc = new LatLng(latitude, longitude);
Marker fuelMarker = map.addMarker(new MarkerOptions().position(subLoc).icon(subwayBitmapDescriptor).title("Subway, " + location));
}
}
Run Code Online (Sandbox Code Playgroud) 我是RavenDB和HangFire的新手,我正在创建一个后台任务但是当我查询ravendb文件时出现索引错误,如下所示:
public static void UpdateDoNotDisturb()
{
IList<HotelRoom> rooms = new List<HotelRoom>();
Hotel project;
IQueryable<HotelRoom> queryableObj;
//Update Rooms with DND status and DndUntil greater than now.
using (var session = MvcApplication.DocumentStore.OpenSession())
{
queryableObj = session.Query<HotelRoom, HotelRoom_Search>().Where(x => x.Status == "DND" && x.DndUntilUtc < DateTime.Now).OfType<HotelRoom>();
//queryableObj = session.Query<HotelRoom, HotelRoom_Search>().Where(x => x.Status == "DND").OfType<HotelRoom>();
using (var enumerator = session.Advanced.Stream(queryableObj))
{
while (enumerator.MoveNext())
{
var room = enumerator.Current.Document;
rooms.Add(room);
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
在文件上:
{
"HotelId": "hotels/1474",
"RoomNumber": "407",
"Floor": "4th Floor",
"Status": "DND", …Run Code Online (Sandbox Code Playgroud)