如何读取 Android 中位于“ASSETS”(或 resources/raw)文件夹中的 GZIP 文件?
我尝试过以下代码,但我的流大小始终为 1。
GZIPInputStream fIn = new GZIPInputStream(mContext.getResources().openRawResource(R.raw.myfilegz));
int size = fIn.available();
Run Code Online (Sandbox Code Playgroud)
由于某种原因,大小始终为 1。但如果我不对该文件进行 GZIP,它就可以正常工作。
注意: 使用Android 1.5
我有一个包含拉丁文、西里尔文和汉字的文本。我尝试使用 GZIPInputStream压缩字符串(超过bytes[])GZIPOutputStream并解压缩它。但我无法将所有字符转换回原始字符。有些显示为?。
我认为 UTF-16 可以完成这项工作。
有什么帮助吗?
问候
这是我的代码:
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;
import java.util.zip.DataFormatException;
import java.util.zip.Deflater;
import java.util.zip.GZIPInputStream;
import java.util.zip.GZIPOutputStream;
import java.util.zip.Inflater;
import java.util.zip.ZipException;
public class CompressUncompressStrings {
public static void main(String[] args) throws UnsupportedEncodingException {
String sTestString="äöüäöü ??";
System.out.println(sTestString);
byte bcompressed[]=compress(sTestString.getBytes("UTF-16"));
//byte bcompressed[]=compress(sTestString.getBytes());
String sDecompressed=decompress(bcompressed);
System.out.println(sDecompressed);
}
public static byte[] compress(byte[] content){
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try{
GZIPOutputStream gzipOutputStream = new GZIPOutputStream(byteArrayOutputStream);
gzipOutputStream.write(content);
gzipOutputStream.close();
} catch(IOException …Run Code Online (Sandbox Code Playgroud) 我的代码有问题:
private static String compress(String str)
{
String str1 = null;
ByteArrayOutputStream bos = null;
try
{
bos = new ByteArrayOutputStream();
BufferedOutputStream dest = null;
byte b[] = str.getBytes();
GZIPOutputStream gz = new GZIPOutputStream(bos,b.length);
gz.write(b,0,b.length);
bos.close();
gz.close();
}
catch(Exception e) {
System.out.println(e);
e.printStackTrace();
}
byte b1[] = bos.toByteArray();
return new String(b1);
}
private static String deCompress(String str)
{
String s1 = null;
try
{
byte b[] = str.getBytes();
InputStream bais = new ByteArrayInputStream(b);
GZIPInputStream gs = new GZIPInputStream(bais);
ByteArrayOutputStream baos …Run Code Online (Sandbox Code Playgroud) 我请求一个发送Content-Encoding:gzip标头的网页,但却被卡住了怎么读它..
我的代码:
try {
URLConnection connection = new URL("http://jquery.org").openConnection();
String html = "";
BufferedReader in = null;
connection.setReadTimeout(10000);
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String inputLine;
while ((inputLine = in.readLine()) != null){
html+=inputLine+"\n";
}
in.close();
System.out.println(html);
System.exit(0);
} catch (IOException ex) {
Logger.getLogger(Crawler.class.getName()).log(Level.SEVERE, null, ex);
}
Run Code Online (Sandbox Code Playgroud)
输出看起来很乱.(我无法在这里粘贴它,一种符号......)
我相信这是一个压缩内容,如何解析呢?
注意:
如果我将jquery.org更改为jquery.com(不发送该标头,我的代码运行良好)
我必须让我自己的 Executor 使用 Spring @Async 注释。为此,我按照以下方式编写了课程
@Configuration
@EnableAsync
public class ConnectedThreads implements AsyncConfigurer {
@Override
public Executor getAsyncExecutor() {
return ...
Run Code Online (Sandbox Code Playgroud)
当我尝试使用此类运行 Spring Boot 应用程序时,应用程序崩溃了
Caused by: java.lang.IllegalStateException: Only one AsyncConfigurer may exist
at org.springframework.scheduling.annotation.AbstractAsyncConfiguration.setConfigurers(AbstractAsyncConfiguration.java:68)
Run Code Online (Sandbox Code Playgroud)
项目中没有其他配置器。这是一个非常小的项目,我可以完全控制它。我自己怀疑自定义配置器可能只是与默认配置器冲突。
有没有可能对 Spring 说这是我需要的配置器,它不应该寻找任何其他配置器?
In TensorFlow's documentation, it is possible to find the following text:
// Not recommended
MatMul m(scope, a, b);
// Recommended
auto m = MatMul(scope, a, b);
Run Code Online (Sandbox Code Playgroud)
I see no obvious benefit from using the "recommended" style. The first version is shorter at least. Also the "recommended" version might include more actions related to the unnecessary assignment operation.
I have read that documentation page no less than six times and still cannot get the rationale behind their reasoning.
Is this …
我在webapp/META-INF /中有以下context.xml.tomcat使用这个来定义Spring将使用Property理解的值
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Parameter name="si.host" value="super.com" override="false"/>
</Context>
Run Code Online (Sandbox Code Playgroud)
现在我试图使用maven jetty插件部署webapp:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.26</version>
<configuration>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>8080</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<jettyEnvXml>${basedir}\src\test\resources\server\jetty\jetty-env.xml</jettyEnvXml>
<jettyConfig>${basedir}\src\test\resources\server\jetty\jetty.xml</jettyConfig >
<contextPath>/myapp</contextPath>
<webApp>target/myapp.war</webApp>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
</configuration>
<executions>
<execution>
<id>start-jetty</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<scanIntervalSeconds>0</scanIntervalSeconds>
<daemon>true</daemon>
</configuration>
</execution>
<execution>
<id>stop-jetty</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
如何在jetty.xml文件中添加此参数?
我已经深入研究了他们的文档,这里和谷歌,但没有发现任何明确的.
在此先感谢您的帮助.
虽然我使用GZIPInputStream来压缩来自Internet的字节,但程序运行错误如下:
05-08 17:37:02.465: W/System.err(744): java.io.IOException: unknown format (magic number 213c)
05-08 17:37:02.465: W/System.err(744): at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:84)
05-08 17:37:02.465: W/System.err(744): at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:64)
05-08 17:37:02.475: W/System.err(744): at com.Android.Sample.TestActivity.onCreate(TestActivity.java:54)
05-08 17:37:02.475: W/System.err(744): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
05-08 17:37:02.475: W/System.err(744): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1611)
05-08 17:37:02.475: W/System.err(744): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1663)
05-08 17:37:02.475: W/System.err(744): at android.app.ActivityThread.access$1500(ActivityThread.java:117)
05-08 17:37:02.475: W/System.err(744): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:931)
05-08 17:37:02.475: W/System.err(744): at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 17:37:02.475: W/System.err(744): at android.os.Looper.loop(Looper.java:123)
05-08 17:37:02.475: W/System.err(744): at android.app.ActivityThread.main(ActivityThread.java:3683)
05-08 17:37:02.475: W/System.err(744): at java.lang.reflect.Method.invokeNative(Native Method)
05-08 17:37:02.475: W/System.err(744): at java.lang.reflect.Method.invoke(Method.java:507)
05-08 17:37:02.475: W/System.err(744): at …Run Code Online (Sandbox Code Playgroud) 我想尝试这样的输出:
555
555
5555
Run Code Online (Sandbox Code Playgroud)
使用代码:
public class Split {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
String phoneNumber = "(555) 555-5555";
String[] splitNumberParts = phoneNumber.split(" |-");
for(String part : splitNumberParts)
System.out.println(part);
Run Code Online (Sandbox Code Playgroud)
但是不知道如何从第一个元素中删除"()".
提前致谢.
问候
该程序没有给出任何输出......如果输入匹配的字符串,函数find_track应返回该轨道.
#include<stdio.h>
#include<string.h>
char tracks[][80] = {
"I left my heart in Harward Med School",
"Newark, Newark - a wonderful town",
"Dancing with a Dork",
"From here to maternity",
"The girl from Iwo Jima",
};
void find_track(char search_for[])
{
int i;
for(i = 0; i< 5 ; i++)
{
if(strstr(tracks[i],search_for))
{
printf("Track %i: '%s'\n",i,tracks[i]);
}
}
}
int main()
{
char search_for[80];
printf("Search for : ");
fgets(search_for,80,stdin);
find_track(search_for);
return 0;
}
Run Code Online (Sandbox Code Playgroud) java ×5
gzip ×3
android ×2
asynchronous ×1
c ×1
c++ ×1
compression ×1
constructor ×1
jetty ×1
spring ×1
spring-boot ×1
string ×1
strstr ×1
tensorflow ×1
tomcat ×1