java.io.StreamCorruptedException: invalid stream header: 77327070是什么情况如何解决? 300C

springboot+datajpa+sqlserver报Caused by: invalid stream header: 77327070是什么情况如何解决?

刚接触springboot+jpa的小白,拜求各路大神的帮忙:
开发工具是eclipse:
没写controller层,先用junit测试crud(即增删改查)中其中的修改和删除,不能用,代码如下:
实体编译好后
1.首先JpaRepository层用的完全是继承JpaRepository的借口自带方法,出查询外没用自定义任何修改:

@Repository

@Transactional

public interface sd extends JpaRepository{
Page findAll(Pageable pageable);

}

```2.service 层是:

@Override

@Modifying

@Transactional
public void delete(String pid) {
    // TODO Auto-generated method stub
    cd.deleteById(pid);
}

@Override
public boolean update(sd sf) {
    // TODO Auto-generated method stub
    cd.save(cfb);
    return true;
}

3.测试类中:

 @Test
 @Modifying
 @Transactional
public void deletepro()  {

    cps.delete("fef232");
}   

    @Test
public void querypro() {
    /* int page=1,size=10;
     Sort sort = new Sort(Direction.DESC, "pid");
     Pageable pageable = new PageRequest(page, size, sort);
     System.out.println(cps.findByPages(pageable));*/

}

``4.具体报错为:

org.hibernate.type.SerializationException: could not deserialize
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]
.......(太长了懒得粘了省略)

**Caused by:

java.io.StreamCorruptedException: invalid stream header: 77327070
**

at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:866) ~[na:1.8.0_191]
at java.io.ObjectInputStream.(ObjectInputStream.java:358) ~[na:1.8.0_191]
at org.hibernate.internal.util.SerializationHelper$CustomObjectInputStream.(SerializationHelper.java:309) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.internal.util.SerializationHelper$CustomObjectInputStream.(SerializationHelper.java:299) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
at org.hibernate.internal.util.SerializationHelper.doDeserialize(SerializationHelper.java:218) ~[hibernate-core-5.3.7.Final.jar:5.3.7.Final]
... 110 common frames omitted

5,配置用的是:application.properties 具体是:

#port is update
server.port=8080
#connection

spring.datasource.driverClassName=com.microsoft.sqlserver.jdbc.SQLServerDriver
spring.datasource.url=jdbc:sqlserver://localhost:1433;DatabaseName=tzc12
spring.datasource.username=sa1
spring.datasource.password=qq
hibernate.dialect=org.hibernate.dialect.SQLServerDialect
spring.jpa.properties.hibernate.show_sql=true
spring.jpa.hibernate.ddl-auto = update

Naming strategy

spring.jpa.hibernate.naming-strategy = org.hibernate.cfg.ImprovedNamingStrategy

#controller

spring.mvc.view.prefix=/

spring.mvc.view.suffix=.jsp
#Connection Pool
spring.datasource.initialSize=5
spring.datasource.minIdle=5
spring.datasource.maxActive=20
spring.datasource.maxWait=60000
spring.datasource.timeBetweenEvictionRunsMillis=60000
spring.datasource.minEvictableIdleTimeMillis=300000
spring.datasource.validationQuery=SELECT 1 FROM DUAL
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=false
spring.datasource.testOnReturn=false


除外,测试查询方法时junit未报错,但出现了以下情况是什么原因?如何解决:
JpaRepository层看最上面
service层:

@Override

    public Page<sd> findByPages(Pageable pageable) {
        // TODO Auto-generated method stub
        return  cd.findAll(pageable);
    }


@Test

    public void querypro() {

         int page=1,size=10;
         Sort sort = new Sort(Direction.DESC, "pid");
         Pageable pageable = new PageRequest(page, size, sort);
         System.out.println(cps.findByPages(pageable));

    }
    结果出来为:

    Page 2 of 1 containing UNKNOWN instances

    更新后:

    实体类:
    sd为主表,cds为附表,即cds 的主键是sd的外键。

    @Entity
@Table(name="cftbiop")
public class sd  implements Serializable{

    /**
     * 
     */
    private static final long serialVersionUID = 8786038170195933216L;



    @Id
    private  String     pid=(UUID.randomUUID().toString()) ;

    private  String     pname ;         

    private String introduction;

    private  String     marque; 

    private  String     showcase; 

    private String      waytoraise  ;   

    private  int        suppot; 

    private  int        raisefunds  ;

    private  int        goalnum    ;

    private cds showid;

    @ManyToOne
    @JoinColumn(name="showid")  
    public cds getShowid() {
        return showid;
    }

    public void setShowid(CFShowProspecification showid) {
        this.showid = showid;
    }
    private  boolean  homepagedisplay;

    private int price;  

    其余getter,setter省略不粘了,都已getter,setter,

    测试查询方法,把page改为0后,报了和删除,修改一样的错误

3个回答

“org.hibernate.type.SerializationException: could not deserialize”
第一个报错是说你的hibernate反序列化失败了,具体可以这样操作:
1,ORM映射,你的hibernate映射文件里面的是否和你实体类对应,表的字段是否对应。
2,实体类是否序列化(实体类implements Serializable接口)。

“Page 2 of 1 containing UNKNOWN instances”
这个错误是说你的页码从1开始根本获取不到数据,应该改为0开始。

qq_34872748
L星火燎原 回复weixin_43944282: 怎么可能,不要把问题搞的那么玄乎,你如果确定跟我的建议是一致,你重新把项目编译一遍,再试试。
大约一年之前 回复
weixin_43944282
weixin_43944282 大佬,我改为0后和修改删除报了同一种问题,字段也对应了
大约一年之前 回复

根据提示, 是由于某个类无法反序列化而造成的。

请把实体类贴出来

weixin_43944282
weixin_43944282 已粘
大约一年之前 回复

你的 sd 是什么? 你的实体类是不是定义的有问题,导致序列化没有成功

C732CDF25D21
Programmer_D_X 回复weixin_43944282: 把序列化去掉吧,你这也不需要序列化,不做网络传输的话
大约一年之前 回复
weixin_43944282
weixin_43944282 实体类
大约一年之前 回复
weixin_43944282
weixin_43944282 实体类、
大约一年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
java.io.StreamCorruptedException: invalid type code: 62
EJB+JBoss+Swing EJB部署在JBoss中,Swing调用EJB中的一个方法A(List<Object) lists),之后就报java.io.StreamCorruptedException: invalid type code: 62. 所传递的集合lists中起初包含一个未序列化的对象,但是我在调用A方法前将其移除后,还是报java.io.StreamCorruptedException: invalid type code: 62. 请大家指点下
Java出现了java.io.StreamCorruptedException
java.io.StreamCorruptedException: invalid type code: 00 如题,我是在做模拟ATM的时候遇到问题 具体问题:java.io.StreamCorruptedException: invalid type code: 00 at java.io.ObjectInputStream.readObject0(Unknown Source) at java.io.ObjectInputStream.readObject(Unknown Source) at programone.ATMMachine2.fileExist(ATMMachine2.java:36) at programone.ATMMachine2.main(ATMMachine2.java:60)
java服务器端出错java.io.StreamCorruptedException
报错信息:java.io.StreamCorruptedException: invalid stream header: 64000000 at java.io.ObjectInputStream.readStreamHeader(Unknown Source) at java.io.ObjectInputStream.<init>(Unknown Source) at org.lxh.server.ServerThreadUtil.run(ServerThreadUtil.java:30) at java.lang.Thread.run(Unknown Source) 出错代码如下: public void run() { // 覆写run()方法 try { PrintStream out = new PrintStream( client.getOutputStream()); // 取得客户端输出流 ObjectInputStream ois = new ObjectInputStream(client .getInputStream()); // 这里出错了 this.upload = (UploadFile) ois.readObject(); // 读取对象 System.out.println("文件标题:" + this.upload.getTitle()); System.out.println("文件类型:" + this.upload.getMimeType()); System.out.println("文件大小:" + this.upload.getContentLength()); out.print(saveFile()); // 返回标记 } catch (Exception e) { e.printStackTrace(); } finally { try { this.client.close(); // 关闭客户端连接 } catch (IOException e) { e.printStackTrace(); } }
java io invalid stream header: 776F7264
``` java.io.StreamCorruptedException: invalid stream header: 776F7264 at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:806) at java.io.ObjectInputStream.<init>(ObjectInputStream.java:299) at dictionary.DictionaryClass.load(DictionaryClass.java:105) at dictionary.DictionaryClass.<init>(DictionaryClass.java:21) at dictionary.Dictionary.<init>(Dictionary.java:14) at dictionary.Dictionary.main(Dictionary.java:19) ``` ``` System.out.println("反序列化进行中"); File f2 = new File("F:\\Text.txt"); ObjectInputStream ois = null; FileInputStream fis = null; try { fis = new FileInputStream(f2); ois = new ObjectInputStream(fis); if (f2.exists()) { System.out.println("反序列化对集合赋值"); this.collection = (ArrayList<DictionaryNum>) ois.readObject(); System.out.println("赋值成功"); ois.close(); } else { ```
Invalid type code: 71
java.io.StreamCorruptedException: Invalid type code: 71这个代码是什么错误 在Oracle上根本找不到有关这个invalid type code:71的任何描述. 所以求大神们解答啊...
android写个注册程序时报java.io.StreamCorruptedException
求大神帮忙看一看,困了好久了,还是解决不了,先上点代码 public void onClick(View v) { if (!userpassword1.getText().toString() .equals(userpassword2.getText().toString())) { Toast.makeText(RegActivity.this, "密码不一致!", Toast.LENGTH_LONG) .show(); return; } Socket socket = null; try { socket = new Socket(Tools.IP, Tools.PORT_1); ObjectOutputStream oout = new ObjectOutputStream( socket.getOutputStream()); ObjectInputStream oin = new ObjectInputStream( socket.getInputStream()); Message m1 = new Message(); Hashtable table = new Hashtable(); table.put("userid", useridText.getText().toString()); if (manb.isChecked()) { table.put("sex", "男"); } else { table.put("sex", "女"); } table.put("username", usernameText.getText().toString()); table.put("age", userageText.getText().toString()); table.put("userpassword", userpassword1.getText().toString()); m1.setValue(table); m1.setType(m1.REG); oout.writeObject(m1); oout.flush(); m1 = (Message) oin.readObject(); if (m1.getReturnValue().get("message").toString() .equalsIgnoreCase("ok")) { AlertDialog.Builder bb = new AlertDialog.Builder( RegActivity.this); bb.setTitle("恭喜您,注册成功!"); bb.setMessage("您的ID是:" + m1.getReturnValue().get("userid")); final String userid = m1.getReturnValue().get("userid") .toString(); bb.setNeutralButton("马上登录", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent in = new Intent(); in.setClass(RegActivity.this, LoginActivity.class); in.putExtra("userid", userid); startActivity(in); RegActivity.this.finish(); } }); bb.setNegativeButton("退出", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { System.exit(0); } }); bb.create().show(); } else { Toast.makeText( RegActivity.this, "注册失败!" + m1.getReturnValue().get("message") .toString(), Toast.LENGTH_LONG) .show(); } } catch (Exception e) { e.printStackTrace(); Toast.makeText(RegActivity.this, "网络不通!"+e.getMessage(), Toast.LENGTH_LONG) .show(); } finally { try { socket.close(); } catch (IOException e) { } } } 在try...catch那捕捉的异常是null; 不知道是不是自己写的服务器的问题,还是软件中的代码错误 报的警告是 java.io.StreamCorruptedException at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1700) at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:1653) at com.erhuo.login.RegActivity$SubmitButtonOnClickListener.onClick(RegActivity.java:88)这里对应的那一行是 m1 = (Message) oin.readObject();
Java socket通信
[size=x-small]是从网上找到的聊天程序 有服务器和客户端, 在注册完之后出现[/size][size=medium]java.io.StreamCorruptedException: invalid stream header: 2A2A2A2A[/size] Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at Register.register(Register.java:293) at Register.actionPerformed(Register.java:202) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236) at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272) at java.awt.Component.processMouseEvent(Component.java:6134) at javax.swing.JComponent.processMouseEvent(JComponent.java:3265) at java.awt.Component.processEvent(Component.java:5899) at java.awt.Container.processEvent(Container.java:2023) at java.awt.Component.dispatchEventImpl(Component.java:4501) at java.awt.Container.dispatchEventImpl(Container.java:2081) at java.awt.Component.dispatchEvent(Component.java:4331) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4301) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3965) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3895) at java.awt.Container.dispatchEventImpl(Container.java:2067) at java.awt.Window.dispatchEventImpl(Window.java:2458) at java.awt.Component.dispatchEvent(Component.java:4331) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122) Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at Login.login(Login.java:189) at Login.actionPerformed(Login.java:155) at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1995) at javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2318) at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:387) at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:242) at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:236) at java.awt.AWTEventMulticaster.mouseReleased(AWTEventMulticaster.java:272) at java.awt.Component.processMouseEvent(Component.java:6134) at javax.swing.JComponent.processMouseEvent(JComponent.java:3265) at java.awt.Component.processEvent(Component.java:5899) at java.awt.Container.processEvent(Container.java:2023) at java.awt.Component.dispatchEventImpl(Component.java:4501) at java.awt.Container.dispatchEventImpl(Container.java:2081) at java.awt.Component.dispatchEvent(Component.java:4331) at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4301) at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3965) at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3895) at java.awt.Container.dispatchEventImpl(Container.java:2067) at java.awt.Window.dispatchEventImpl(Window.java:2458) at java.awt.Component.dispatchEvent(Component.java:4331) at java.awt.EventQueue.dispatchEvent(EventQueue.java:599) at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:269) at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:184) at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:174) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:169) at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:161) at java.awt.EventDispatchThread.run(EventDispatchThread.java:122)[/size]
java.io.StreamCorruptedException
今天碰到个问题已经困扰我一天了 使用MultipartFile读取了一个xlsx的文件 再转换成 ObjectInputStream 读取里面的内容 报了下图所示的错误 ![图片说明](https://img-ask.csdn.net/upload/201708/24/1503570274_399205.png) 所写代码如下 ![图片说明](https://img-ask.csdn.net/upload/201708/24/1503570210_458120.png) 这是读取的文件内容 ![图片说明](https://img-ask.csdn.net/upload/201708/24/1503570232_947109.png) ![图片说明](https://img-ask.csdn.net/upload/201708/24/1503570247_424604.png)
elasticsearch插入数据报错
之前用的elasticsearch是1.3.2版本的,装了ik插件,用起来很正常,后面elasticsearch换成2.0.0的了,还装了logstash2.0.0,kibana4.2.0, ik分词器是1.5.0的,用Java代码批量插入的时候就报错了,在elasticsearch的控制台手动插入是没问题的 [INFO][2016-11-16 18:22:34] org.elasticsearch.plugins.PluginsService.<init>(PluginsService.java:151) main [Agatha Harkness] loaded [analysis-jcseg], sites [] [INFO][2016-11-16 18:22:35] org.elasticsearch.client.transport.TransportClientNodesService$SniffNodesSampler$1$1.handleException(TransportClientNodesService.java:443) elasticsearch[Agatha Harkness][transport_client_worker][T#1]{New I/O worker #28} [Agatha Harkness] failed to get local cluster state for [#transport#-1][USER-20150529VW][inet[localhost/127.0.0.1:9300]], disconnecting... org.elasticsearch.transport.RemoteTransportException: Failed to deserialize exception response from stream Caused by: org.elasticsearch.transport.TransportSerializationException: Failed to deserialize exception response from stream at org.elasticsearch.transport.netty.MessageChannelHandler.handlerResponseError(MessageChannelHandler.java:173) at org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:125) at org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) at org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791) at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:296) at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462) at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:443) at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303) at org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559) at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:268) at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:255) at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88) at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108) at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318) at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89) at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178) at org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108) at org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.io.StreamCorruptedException: Unsupported version: 1 at org.elasticsearch.common.io.ThrowableObjectInputStream.readStreamHeader(ThrowableObjectInputStream.java:46) at java.io.ObjectInputStream.<init>(ObjectInputStream.java:299) at org.elasticsearch.common.io.ThrowableObjectInputStream.<init>(ThrowableObjectInputStream.java:38) at org.elasticsearch.transport.netty.MessageChannelHandler.handlerResponseError(MessageChannelHandler.java:170) ... 23 more [WARN][2016-11-16 18:22:35] org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:135) elasticsearch[Agatha Harkness][transport_client_worker][T#1]{New I/O worker #28} [Agatha Harkness] Message not fully read (response) for [0] handler org.elasticsearch.client.transport.TransportClientNodesService$SniffNodesSampler$1$1@7e8c9412, error [true], resetting [INFO][2016-11-16 18:22:39] org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:862) Thread-1 Closing org.springframework.context.support.GenericApplicationContext@fbd1f6: startup date [Wed Nov 16 18:21:55 CST 2016]; root of context hierarchy [INFO][2016-11-16 18:22:39] org.elasticsearch.node.internal.InternalNode.stop(InternalNode.java:272) Thread-1 [Fer-de-Lance] stopping ... [INFO][2016-11-16 18:22:39] org.elasticsearch.node.internal.InternalNode.stop(InternalNode.java:310) Thread-1 [Fer-de-Lance] stopped
使用elasticsearch批量插入数据报错
之前用的是elasticsearch1.3.2的版本加了ik分词器测试过是没有问题的,后来换成2.0.0版本的,同时安装了logstash2.0.0和kibana4.2.0,ik分词器是1.5.0的,然后再用Java代码运行的时候就报错,实在是看不懂 [INFO][2016-11-16 17:54:24] org.elasticsearch.plugins.PluginsService.<init>(PluginsService.java:151) main [Abdul Alhazred] loaded [analysis-jcseg], sites [] [INFO][2016-11-16 17:54:24] org.elasticsearch.client.transport.TransportClientNodesService$SniffNodesSampler$1$1.handleException(TransportClientNodesService.java:443) elasticsearch[Abdul Alhazred][transport_client_worker][T#1]{New I/O worker #28} [Abdul Alhazred] failed to get local cluster state for [#transport#-1][USER-20150529VW][inet[localhost/127.0.0.1:9300]], disconnecting... org.elasticsearch.transport.RemoteTransportException: Failed to deserialize exception response from stream Caused by: org.elasticsearch.transport.TransportSerializationException: Failed to deserialize exception response from stream at org.elasticsearch.transport.netty.MessageChannelHandler.handlerResponseError(MessageChannelHandler.java:173) at org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:125) at org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) at org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791) at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:296) at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462) at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:443) at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303) at org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559) at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:268) at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:255) at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88) at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108) at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318) at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89) at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178) at org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108) at org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) at java.lang.Thread.run(Thread.java:745) Caused by: java.io.StreamCorruptedException: Unsupported version: 1 at org.elasticsearch.common.io.ThrowableObjectInputStream.readStreamHeader(ThrowableObjectInputStream.java:46) at java.io.ObjectInputStream.<init>(ObjectInputStream.java:299) at org.elasticsearch.common.io.ThrowableObjectInputStream.<init>(ThrowableObjectInputStream.java:38) at org.elasticsearch.transport.netty.MessageChannelHandler.handlerResponseError(MessageChannelHandler.java:170) ... 23 more [WARN][2016-11-16 17:54:24] org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:135) elasticsearch[Abdul Alhazred][transport_client_worker][T#1]{New I/O worker #28} [Abdul Alhazred] Message not fully read (response) for [0] handler org.elasticsearch.client.transport.TransportClientNodesService$SniffNodesSampler$1$1@29f1fa67, error [true], resetting [INFO][2016-11-16 17:54:28] org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:862) Thread-1 Closing org.springframework.context.support.GenericApplicationContext@fbd1f6: startup date [Wed Nov 16 17:53:44 CST 2016]; root of context hierarchy [INFO][2016-11-16 17:54:28] org.elasticsearch.node.internal.InternalNode.stop(InternalNode.java:272) Thread-1 [Killer Shrike] stopping ... [INFO][2016-11-16 17:54:28] org.elasticsearch.node.internal.InternalNode.stop(InternalNode.java:310) Thread-1 [Killer Shrike] stopped
为什么 elasticsearch 获取节点信息失败?
在 spring boot 项目中即成集成 elasticsearch(dao层数据与es交互使用的的是 spring-data-elasticsearch)首先安装了服务器端的 es 服务,和 head 插件,es 服务启动正常,node-1 为默认主节点,my-cluster 为集群名,如图: ![图片说明](https://img-ask.csdn.net/upload/201605/24/1464076273_991814.png) 在程序中,使用嵌入式node启动节点正常,方式如下: ``` Node node = NodeBuilder.nodeBuilder().node(); node.start(); ``` 但是,如果使用 TransportClient 建立 es 的 Client,方式如下: ``` TransportClient client = new TransportClient(settings); client.addTransportAddress(new InetSocketTransportAddress("127.0.0.1", 9300)); ``` 这是 ES 2.3 官网上面提供的 TransportClient 方式:https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/transport-client.html 使用 TransportClient 方式,启动程序后,程序可以正常启动,但是控制台一直不停报错,貌似是在一直监测节点,而节点一直没有被发现,所以不停报错,错误信息如下,应用程序控制台错误信息: ``` 2016-05-23 19:40:15.823 INFO 27655 --- [ main] org.elasticsearch.client.transport : [Aliyah Bishop] failed to get node info for [#transport#-1][XXX-MBP.lan][inet[/127.0.0.1:9300]], disconnecting... org.elasticsearch.transport.RemoteTransportException: Failed to deserialize exception response from stream Caused by: org.elasticsearch.transport.TransportSerializationException: Failed to deserialize exception response from stream at org.elasticsearch.transport.netty.MessageChannelHandler.handlerResponseError(MessageChannelHandler.java:173) at org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:125) at org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) at org.elasticsearch.common.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791) at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:296) at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462) at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:443) at org.elasticsearch.common.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303) at org.elasticsearch.common.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) at org.elasticsearch.common.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559) at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:268) at org.elasticsearch.common.netty.channel.Channels.fireMessageReceived(Channels.java:255) at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88) at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108) at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:318) at org.elasticsearch.common.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89) at org.elasticsearch.common.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178) at org.elasticsearch.common.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108) at org.elasticsearch.common.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) Caused by: java.io.StreamCorruptedException: Unsupported version: 1 at org.elasticsearch.common.io.ThrowableObjectInputStream.readStreamHeader(ThrowableObjectInputStream.java:46) at java.io.ObjectInputStream.<init>(ObjectInputStream.java:299) at org.elasticsearch.common.io.ThrowableObjectInputStream.<init>(ThrowableObjectInputStream.java:38) at org.elasticsearch.transport.netty.MessageChannelHandler.handlerResponseError(MessageChannelHandler.java:170) ... 23 common frames omitted …………. failed to load elasticsearch nodes : org.elasticsearch.client.transport.NoNodeAvailableException: None of the configured nodes are available: [] ``` es 控制台报错信息: ``` [2016-05-23 21:45:56,807][WARN ][transport.netty ] [node-1] exception caught on transport layer [[id: 0x8e4b89bc, /127.0.0.1:62566 => /127.0.0.1:9300]], closing connection java.lang.IllegalStateException: Message not fully read (request) for requestId [233], action [cluster/nodes/info], readerIndex [39] vs expected [57]; resetting at org.elasticsearch.transport.netty.MessageChannelHandler.messageReceived(MessageChannelHandler.java:121) at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791) at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296) at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462) at org.jboss.netty.handler.codec.frame.FrameDecoder.callDecode(FrameDecoder.java:443) at org.jboss.netty.handler.codec.frame.FrameDecoder.messageReceived(FrameDecoder.java:303) at org.jboss.netty.channel.SimpleChannelUpstreamHandler.handleUpstream(SimpleChannelUpstreamHandler.java:70) at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) at org.jboss.netty.channel.DefaultChannelPipeline$DefaultChannelHandlerContext.sendUpstream(DefaultChannelPipeline.java:791) at org.elasticsearch.common.netty.OpenChannelsHandler.handleUpstream(OpenChannelsHandler.java:75) at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:564) at org.jboss.netty.channel.DefaultChannelPipeline.sendUpstream(DefaultChannelPipeline.java:559) at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268) at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255) at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88) at org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:108) at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:337) at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:89) at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178) at org.jboss.netty.util.ThreadRenamingRunnable.run(ThreadRenamingRunnable.java:108) at org.jboss.netty.util.internal.DeadLockProofWorker$1.run(DeadLockProofWorker.java:42) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) at java.lang.Thread.run(Thread.java:745) ``` 而且,当我使用嵌入式node启动节点后,系统会自动启动一个node节点,node.name 也是随机的,并且并没有将该节点加入启动的es集群中,我加入的索引和数据也不能出现在 my-cluster 集群中 所以有两个问题: 1、为什么我使用嵌入式node启动节点,启动后的节点不会加入到集群中? 2、使用 TransportClient 方式建立 Client,启动程序后,程序的控制台,和服务器端的es一直报错,获取节点信息失败,是什么原因?即上面的错误信息 下面是环境版本信息: 服务器端 es 版本:2.3.3 jdk 版本:1.7.0_79 spring-data-elasticsearch 版本:1.2.0.RELEASE(即:elasticsearch-1.4.4.jar) 服务器端 es 配置,elasticsearch.yml: cluster.name: my-cluster node.name: node-1 http 端口为:9200 节点间的通信端口为:9300 关于第二个问题尝试了很多解决方案,比如: 1、应用 和 es 的 jdk 环境版本不一致。已检查过一致 https://github.com/elastic/elasticsearch/issues/3835 2、es 多个节点之间的JDK版本不一致。我使用的只是单节点,并且都在我本地机器上 http://jontai.me/blog/2013/06/elasticsearch-remotetransportexception-failed-to-deserialize-exception-response-from-stream/ 3、idk 版本过低,建议1.7+。已是1.7+ 最后附上两种启动节点方式的完整代码 1、嵌入式 node 启动 ``` import org.elasticsearch.client.Client; import org.elasticsearch.node.Node; import org.elasticsearch.node.NodeBuilder; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; @Configuration @EnableElasticsearchRepositories(basePackages = "xx.xxx.domain.repository.elastic") public class ElasticsearchConfiguration { @Bean public Client client() { Node node = NodeBuilder.nodeBuilder().node(); node.start(); return node.client(); } } ``` 2、TransportClient 方式 ``` import org.elasticsearch.client.Client; import org.elasticsearch.client.transport.TransportClient; import org.elasticsearch.common.settings.ImmutableSettings; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.transport.InetSocketTransportAddress; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.elasticsearch.core.ElasticsearchOperations; import org.springframework.data.elasticsearch.core.ElasticsearchTemplate; import org.springframework.data.elasticsearch.repository.config.EnableElasticsearchRepositories; @Configuration @EnableElasticsearchRepositories(basePackages = "xx.xxx.domain.repository.elastic") public class ElasticsearchConfiguration { @Bean public Client client() { TransportClient client = new TransportClient(); client.addTransportAddress(new InetSocketTransportAddress("127.0.0.1", 9300)); return client; } @Bean public ElasticsearchOperations elasticsearchTemplate() { return new ElasticsearchTemplate(client()); } } ```
关于安卓byte数组转Obj的问题
各位大侠好,App与服务器通过byte数组的形式来传输某个类,App这边接收的时候执行byte数组转Object时总是报错:java.io.StreamCorruptedException,下面是异常信息: ``` V/ObjDebug: ??��sr��com.wanshang.po.Users����������������I��idF��pointL��namet��Ljava/lang/String;L��passwordq��~��L�� paypasswordq��~��L��phoneq��~��L��usertypeq��~��xp������E?v��t��jatt��123456t��*t�� 18819257754t��customer W/System.err: java.io.StreamCorruptedException W/System.err: at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:2067) W/System.err: at java.io.ObjectInputStream.<init>(ObjectInputStream.java:372) W/System.err: at com.wanshang.wanshangapplication.tools.DataTools.byteToObj(DataTools.java:59) W/System.err: at com.wanshang.wanshangapplication.tools.HttpUtils.dealResponseResult(HttpUtils.java:104) W/System.err: at com.wanshang.wanshangapplication.tools.HttpUtils.postData(HttpUtils.java:51) W/System.err: at com.wanshang.wanshangapplication.ui.MainActivity$6.run(MainActivity.java:195) W/System.err: at java.lang.Thread.run(Thread.java:841) ``` 乱码部分是byte数组的输出,可以看到有类的属性名,就是转换成Object的时候出问题,下面是转换代码: ``` //数组转对象 public Object byteToObj (byte[] bytes) { Object obj = null; try { ByteArrayInputStream bis = new ByteArrayInputStream (bytes); ObjectInputStream ois = new ObjectInputStream (bis); obj = ois.readObject(); ois.close(); bis.close(); } catch (Exception e) { e.printStackTrace(); } return obj; } ``` 请问这个问题该如何解决?
jasperreport+applet实现客户端打印报表
本人使用ireport5.1.0画的报表,实现客户端打印时报java.io.StreamCorruptedException:invalid stream header:0D0A0D0A这个错误,下面是代码,请各位高手帮忙看看怎么回事: 1)、action类代码 import java.io.File; import java.io.ObjectOutputStream; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.HashMap; import java.util.Map; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletResponse; import net.sf.jasperreports.engine.JRResultSetDataSource; import net.sf.jasperreports.engine.JasperFillManager; import net.sf.jasperreports.engine.JasperPrint; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; public class IreportAction extends ActionSupport{ private static final long serialVersionUID = 1974082731836773155L; private static final String CONTENTTYPE = "application/octet-stream"; /** * 打印报表 * @return */ @SuppressWarnings("unchecked") public void doIreportPrint(){ HttpServletResponse response = ServletActionContext.getResponse(); String fileName = ""; String sql = "select id,dname,dcode from ct_su_departments where datalevel = 0 and status = 0 and rownum <=100"; //建立连接 Connection conn = this.createConnection(); //参数设置 Map parameters = new HashMap(); try { Statement stmt = conn.createStatement();//获取数据库链接 ResultSet rs = stmt.executeQuery(sql);//获取数据 String jasper = new File(ServletActionContext.getServletContext().getRealPath("/report/report1.jasper")).getPath();//获取文件的绝对路径 JasperPrint jpt = JasperFillManager.fillReport(jasper, parameters, new JRResultSetDataSource(rs));//匹配数据源,生成JasperPrint response.setContentType(CONTENTTYPE); ServletOutputStream ouputStream = response.getOutputStream(); ObjectOutputStream oos = new ObjectOutputStream(ouputStream); oos.writeObject(jpt); oos.flush(); oos.close(); }catch(Exception e) { System.out.println("Error:" + e.toString()); e.printStackTrace(); }finally { CloseConnect(conn); conn = null; } } /** * 建立数据库连接 * @return */ public Connection createConnection(){ Connection conn; try{ String driver = "oracle.jdbc.driver.OracleDriver";//oracle.jdbc.OracleDriver String url = "jdbc:oracle:thin:@172.19.24.239:1521:NSOA"; Class.forName(driver); conn = DriverManager.getConnection(url,"JXKHOA","JXKHOA"); conn.setAutoCommit(false); return conn; }catch(SQLException e1) { System.out.println("建立连接错误 = " + e1.toString()); e1.printStackTrace(); }catch(ClassNotFoundException e2) { System.out.println("建立连接错误 = " + e2.toString()); e2.printStackTrace(); } return null; } /** * 关闭数据库连接 * @param conn */ public void CloseConnect(Connection conn){ try{ conn.commit(); conn.setAutoCommit(true); conn.close(); }catch(Exception e){ System.out.println("关闭连接错误 = " + e.toString()); } } } 2)japplet代码: import java.io.PrintWriter; import java.io.StringWriter; import java.net.URL; import javax.swing.JOptionPane; import net.sf.jasperreports.engine.JasperPrint; import net.sf.jasperreports.engine.JasperPrintManager; import net.sf.jasperreports.engine.util.JRLoader; public class IreportApplet extends javax.swing.JApplet{ private static final long serialVersionUID = 2525694418170444107L; private URL url = null; private JasperPrint jasperPrint = null; public void init(){ String strUrl = "http://172.19.24.28:8100/BaseWeb/ireportPrint.action"; if (strUrl != null){ try{ URL urll = new URL(strUrl); url = urll; System.out.println("url="+urll); }catch (Exception e){ StringWriter swriter = new StringWriter(); PrintWriter pwriter = new PrintWriter(swriter); e.printStackTrace(pwriter); JOptionPane.showMessageDialog(this, swriter.toString()); } }else{ JOptionPane.showMessageDialog(this, "init():Source URL not specified"); } } public void start(){ if (url != null){ if (jasperPrint == null){ try{ jasperPrint = (JasperPrint)JRLoader.loadObject(url); }catch (Exception e){ StringWriter swriter = new StringWriter(); PrintWriter pwriter = new PrintWriter(swriter); e.printStackTrace(pwriter); JOptionPane.showMessageDialog(this, swriter.toString()); } } if (jasperPrint != null){ final JasperPrint print = jasperPrint; Thread thread = new Thread(new Runnable(){ public void run(){ try{ System.out.println("进入start方法,即将打印pdf文件"); JasperPrintManager.printReport(print, true); }catch (Exception e){ StringWriter swriter = new StringWriter(); PrintWriter pwriter = new PrintWriter(swriter); e.printStackTrace(pwriter); JOptionPane.showMessageDialog(null, swriter.toString()); } } }); thread.start(); }else{ JOptionPane.showMessageDialog(this, "Empty report."); } }else{ JOptionPane.showMessageDialog(this, "start():Source URL not specified"); } } } 执行到jasperPrint = (JasperPrint)JRLoader.loadObject(url);这就话是就报错了。该报表导出excel和pdf都是可以的,而且在action类里面直接使用JasperViewer.viewReport(jpt,false);也是可以打印的,就这个japplet生成客户端打印时报错了。希望各位高手能赐教,非常感谢!!!
大家来帮忙啊,一个异常问题,好几天了,还没有解决
<p><span class="Apple-style-span" style=""><span class="Apple-style-span" style="text-align: left; line-height: 12px; font-family: 'Trebuchet MS', 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 13px;"></span></span> </p> <p> </p> <p>但是基本上都没有找到解决方法,头都晕了,麻烦各位路过的大哥大姐帮忙<img src="/images/smiles/icon_mad.gif" alt=""></p> <h1 style="background-color: transparent; margin: 0px 0px 7px; font-family: 'Trebuchet MS', 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 23px; vertical-align: baseline; font-weight: bold; border-width: 0px; padding: 0px;"><span style="font-size: small;">在我写的服务器与客户端通信时,有时候出现下面的异常,有时候不出现,我在网上差了很多资料,但是都没有找到能够解决的方法</span></h1> <h1 style="background-color: transparent; margin: 0px 0px 7px; font-family: 'Trebuchet MS', 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 23px; vertical-align: baseline; font-weight: bold; border-width: 0px; padding: 0px;"><a class="question-hyperlink" style="background-color: transparent; margin: 0px; color: #000000; font-size: 23px; vertical-align: baseline; cursor: pointer; font-weight: bold; text-decoration: none; border-width: 0px; padding: 0px;" href="http://stackoverflow.com/questions/2393179/streamcorruptedexception-invalid-type-code-ac"><span style="font-size: small;"><span style="text-decoration: underline;">StreamCorruptedException: invalid type code: AC</span></span></a></h1> <p style="background-color: transparent; margin: 0px 0px 7px; font-family: 'Trebuchet MS', 'Liberation Sans', 'DejaVu Sans', sans-serif; font-size: 23px; vertical-align: baseline; font-weight: bold; border-width: 0px; padding: 0px;"><span style="font-size: small;">还有这个帖子说这是java的一个bug</span></p> <p> </p> <h1><a class="question-hyperlink" href="http://www.iteye.com/questions/2234406/exception-java-io-streamcorruptedexception-invalid-type-code-00"><span style="color: #000000; font-size: small;">Exception: java.io.StreamCorruptedException: invalid type code: 00</span></a></h1> <h1><span style="font-size: small;">网上还有帖子说“这是因为一个线程中定义了多个objectOutputStream”</span></h1> <p><a href="http://hi.baidu.com/ltolt/blog/item/d2de5571fc4622108701b0b1.html"><span style="font-size: small;">http://hi.baidu.com/ltolt/blog/item/d2de5571fc4622108701b0b1.html</span></a></p> <p> </p> <p><span style="font-size: small;">还有说法是要重写writeStreamHeader</span></p> <p> </p> <p><a href="http://hi.baidu.com/%CE%F7%D1%E3%B4%F3%B4%F3/blog/item/bd3d99eb6fc37006fcfa3c8d.html"><span style="font-size: small;">http://hi.baidu.com/%CE%F7%D1%E3%B4%F3%B4%F3/blog/item/bd3d99eb6fc37006fcfa3c8d.html</span></a></p><br/><strong>问题补充</strong><br/><div class="quote_title">lan861698789 写道</div><div class="quote_div">呵呵,看看</div><br />求教,好久了,没有解决
socket怎么接收复数次消息
我想实现socket多次接收数据,但是只能收到第一次数据,第二次接收会提示java.io.StreamCorruptedException,请问这块我应该怎么改,代码如下。 while (true) { // 输入流 InputStream is = null; is = socket.getInputStream(); ObjectInputStream in = new ObjectInputStream(is); TimeMessage timeMessageGet = null; timeMessageGet = new TimeMessage(); timeMessageGet = (TimeMessage) in.readObject(); if (timeMessageGet != null) { status = timeMessageGet.getStatusString(); time = timeMessageGet.getNextTimeLong(); // 反馈 os = socket.getOutputStream(); ObjectOutputStream out = new ObjectOutputStream(os); TimeMessage timeMessageSend = new TimeMessage(); timeMessageSend.setStatusString(STATUS_GOT); timeMessageSend.setNextTimeLong(123); out.writeObject(timeMessageSend); out.flush(); System.out.println("send got"); if (status.equals(STATUS_TEST_BEGIN)) { // 开始测试 System.out.println("got begin"); } else { System.out.println("收到错误status"); } } } } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); }
objectinputstream readobject 为何只能读取第一次写入的值
public class TransEntity implements Serializable//传输信息实体封装类 { private static final long serialVersionUID = 1L; private String operaType;//用户操作类型;如发送文本消息,发送语音消息,发送音频消息 private String responseTags;//网络响应状态;如“登录成功”、“登录失败”、“注册成功”、“注册失败” private String requestTags;//网络请求标记;请求发送文本消息,语音消息,音频消息 private User sender;//发送方; private User receiver;//接收方; private ArrayList<HashMap<String,Object>> buddylist;//好友列表信息; private String time;//系统时间; private ArrayList<HashMap<String,String>> inputGeneralMsgList;//通用信息 private HashMap<String,Object> outGeneralMsgMap; private String path; public String getUserOperaType() { return operaType; } public void setUserOperaType(String operaType) { this.operaType = operaType; } public String getResponseTags() { return responseTags; } public String setResponseTags(String responseTags) { return this.responseTags = responseTags; } public void setRequestTags(String requestTags) { this.requestTags = requestTags; } public String getRequestTags() { return requestTags; } public User getSender() { return sender; } public void setSender(User sender) { this.sender = sender; } public User getReceiver() { return receiver; } public void setReceiver(User receiver) { this.receiver = receiver; } public ArrayList<HashMap<String,Object>> getList() { return buddylist; } public void setList(ArrayList<HashMap<String,Object>> buddylist) { this.buddylist = buddylist; } public String getImagePath() { return path; } public void setImagePath(String path) { this.path = path; } public void setGeneralMessagefrom(ArrayList<HashMap<String,String>> inputGeneralMsgList) { this.inputGeneralMsgList = inputGeneralMsgList; } public ArrayList<HashMap<String,String>> getGeneralMessagefrom() { return inputGeneralMsgList; } public void setGeneralMessageto(HashMap<String,Object> outGeneralMsgMap) { this.outGeneralMsgMap = outGeneralMsgMap; } public HashMap<String,Object> getGeneralMessageto() { return outGeneralMsgMap; } public void setSysTime(String time) { this.time = SysTime.getDateTime(); } public String getSysTime() { return time; } } 服务端核心代码 public class ServerThread extends Thread { private static ObjectInputStream ois = null; private static ObjectOutputStream oos = null; private ArrayList<HashMap<String,Object>> list = null; private ArrayList<HashMap<String,String>> outgeneralMsgList = null; private Socket socket = null; private TransEntity trans = null; private boolean FLAGS_IsFirstLogin = true; private boolean FLAGS_LoginSucess = false; private boolean FLAGS_RegisterSucess = false; private boolean FLAGS_OnLine = false; private User user = null; private User receiver = null; private Timer timer = new Timer(); public ServerThread(Socket socket) { this.socket = socket; try { oos = new ObjectOutputStream(socket.getOutputStream()); ois = new ObjectInputStream(socket.getInputStream()); } catch (IOException e) { e.printStackTrace(); } } public void run() { try { while(true) { if(socket.isClosed() == false && socket.isConnected() == true) { try { if(ois!=null) { trans = (TransEntity) ois.readObject(); } } catch(java.net.SocketException e) { System.out.println("客户端已经关闭。。。。。。。"); break; } catch(ClassNotFoundException e) { System.out.println("--------空指针异常---------"); } catch(java.io.EOFException e) { System.out.println("客户端已经关闭。。。。。。。"); } } if(trans!=null) { user = trans.getSender(); receiver = trans.getReceiver(); if(trans.getUserOperaType()!=null) { System.out.println("----------trans.getUserOperaType() :------------"+(trans.getUserOperaType())); if(FLAGS_IsFirstLogin == true&&(UserOperaType.LOGIN.equals(trans.getUserOperaType()))) { //首次登录,一般情形下的客户端发过来的登录操作请求做处理,非掉线后的自动登录; System.out.println("--------server---socket :------"+(socket)); FLAGS_LoginSucess = setLogin(); } if(FLAGS_LoginSucess) { FLAGS_IsFirstLogin = false; System.out.println("----------trans.getUserOperaType() :------------"+(trans.getUserOperaType())); ......为何此次只能输出第一次读入的数据 if(UserOperaType.SEND_MESSAGE.equals(trans.getUserOperaType())) { System.out.println("-------UserOperaType.SEND_MESSAGE ---------"); System.out.println(trans.getGeneralMessageto().get("outMsg").toString()); if(trans.getGeneralMessageto()!=null)//若getGeneralMessageto()返回值不为空,则可以向数据库写入信息; { System.out.println("-------服务端:---发送方 写入普通信息到数据库,如文字消息;-----------"); SysCtlVar.dbBasicOperation.writeGeneralMessage(trans);// 发送方 写入普通信息到数据库,如文字消息; //trans.setGeneralMessageto(null); } trans.setUserOperaType(null); } oos.writeObject(trans); oos.flush(); } } } } } catch (Exception e) { e.printStackTrace(); } finally { } } } 客户端核心代码 while(SysCtlVar.FlAGS_LoginSuccess) { // System.out.println("--------------while SysCtlVar.FlAGS_LoginSuccess -------------"); try { try { SysCtlVar.trans = (TransEntity)SysCtlVar.ois.readObject(); if(SysCtlVar.inputGeneralMsgList!=null) synchronized(SysCtlVar.inputGeneralMsgList) { SysCtlVar.inputGeneralMsgList = SysCtlVar.trans.getGeneralMessagefrom(); SysCtlVar.inputGeneralMsgList.notify(); } synchronized(SysCtlVar.outGeneralMsgMap) { try { System.out.println("------- SysCtlVar.outGeneralMsgMap.wait----------"); SysCtlVar.outGeneralMsgMap.wait(); //等待直到有输入的时候,才把消息发送出去 System.out.println("---------------客户端: 正在发送消息。。。。。。------------------"); System.out.println("------- SysCtlVar.outGeneralMsgMap:----------"+(SysCtlVar.outGeneralMsgMap.get("outMsg").toString())); SysCtlVar.trans.setUserOperaType(UserOperaType.SEND_MESSAGE); SysCtlVar.trans.setGeneralMessageto(SysCtlVar.outGeneralMsgMap); System.out.println("------- SysCtlVar.trans.getGeneralMessageto():----------"+(SysCtlVar.trans.getGeneralMessageto().get("outMsg").toString())); try { SysCtlVar.oos.writeObject(SysCtlVar.trans); SysCtlVar.oos.flush(); } catch (IOException e) { e.printStackTrace(); } } catch (InterruptedException e) { e.printStackTrace(); } } } catch (ClassNotFoundException e) { e.printStackTrace(); } } catch (StreamCorruptedException e1) { e1.printStackTrace(); } catch (IOException e1) { e1.printStackTrace(); } } } 客户端 数据输入部分 /** 调试过程中,你将看到客户端输入的消息为h(第一条消息),www(第二条消息),a(第三条消息) 但是服务端只有第二条消息的值; */ //------------------发送消息 ---------- //客户端当前会话任务中,选中的消息接收者; new Thread() { public void run() { synchronized(SysCtlVar.outGeneralMsgMap) { System.out.println("------- 客户端:正在输入要发送的消息----------"); SysCtlVar.outGeneralMsgMap.clear(); SysCtlVar.outGeneralMsgMap.put("outMsg",outMsg); SysCtlVar.outGeneralMsgMap.put("msgRecver", selectedAccount); SysCtlVar.outGeneralMsgMap.put("dateTime",SysTime.getDateTime().toString()); SysCtlVar.outGeneralMsgMap.notify(); //输入完毕,通知发送任务执行 } } }.start(); 调试信息(服务器端) 服务器已启动,正在监听1345端口 ----------trans.getUserOperaType() :------------0 --------server---socket :------Socket[addr=/127.0.0.1,port=38516,localport=1345] ------- list!=null : ---------true [qq]上线了! ----------qq---------- ----------trans.getUserOperaType() :------------0 ----------trans.getUserOperaType() :------------6 ----------trans.getUserOperaType() :------------6 -------------UserOperaType.GET_AVATARS------------6 我想从服务器获取头像 ----------trans.getUserOperaType() :------------7 ----------trans.getUserOperaType() :------------7 -------UserOperaType.SEND_MESSAGE --------- www -------服务端:---发送方 写入普通信息到数据库,如文字消息;----------- insert into chat(sender,recver,message,sendtime) values('qq','在水一方','www','2015-04-24 16:15:13') ----------trans.getUserOperaType() :------------7 ----------trans.getUserOperaType() :------------7 -------UserOperaType.SEND_MESSAGE --------- www -------服务端:---发送方 写入普通信息到数据库,如文字消息;----------- insert into chat(sender,recver,message,sendtime) values('qq','在水一方','www','2015-04-24 16:15:13') ----------trans.getUserOperaType() :------------7 ----------trans.getUserOperaType() :------------7 -------UserOperaType.SEND_MESSAGE --------- www -------服务端:---发送方 写入普通信息到数据库,如文字消息;----------- insert into chat(sender,recver,message,sendtime) values('qq','在水一方','www','2015-04-24 16:15:13') ----------trans.getUserOperaType() :------------7 ----------trans.getUserOperaType() :------------7 -------UserOperaType.SEND_MESSAGE --------- www -------服务端:---发送方 写入普通信息到数据库,如文字消息;----------- insert into chat(sender,recver,message,sendtime) values('qq','在水一方','www','2015-04-24 16:15:13') ---------------问题补充--------------- 单步调试,客户端的输出流正确发送了每一次的客户端输入数据(36分钟前)删除 对于单步调试追踪的结果:客户端每一次发送的trans(它是TransEntity的实例,被序列化的消息实体对象)都是正确的(即,与客户端输入值相同)。但是服务端有ObjectInputStream读入的trans(它也是TransEntity的实例,被序列化的消息实体对象)却没有改变始终是第一次的值
android中序列化的StreamCorruptedException异常
在反序列化过程中执行到 ObjectInputStream objectInputStream=new ObjectInputStream(inputStream);这一步时抛出StreamCorruptedException异常。这个异常很少见啊,请问怎么办。。。 public AccessTokenObject deSerialize(String str){ AccessTokenObject object=null; try { String readStr=java.net.URLEncoder.encode(str,"UTF-8"); byte[] bytes=readStr.getBytes("ISO-8859-1"); ByteArrayInputStream inputStream=new ByteArrayInputStream(bytes); ObjectInputStream objectInputStream=new ObjectInputStream(inputStream); object=(AccessTokenObject)objectInputStream.readObject(); inputStream.close(); objectInputStream.close(); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } catch (StreamCorruptedException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (ClassNotFoundException e) { e.printStackTrace(); } return object; }
关于android手机接收空调机返回数据显示的编程问题。
这个是关于用android手机接收空调机返回数据显示的编程问题: 在主页HomeActivtiy.java里面,接收空调传过来的数据代码是: private Runnable mLoop = new Runnable() { //被上面实例调用 public void run() { int len; byte[] rbuf = new byte[128]; do { len = mSerial.read(rbuf); //return mSerial.read(rbuf,rbuf.length) (注意:这个就是接收空调机的函数) // rbuf[len] = 0; if (len > 0) { if (len == 35) { System.arraycopy(rbuf, 0, mReceiveByte.data, 0, 35);//《J6》第64页 mReceiveByte.length = 0; //这里是给它赋值; 这里与if (mReceiveByte.length != 0) 比较;调用下面的类 CheckReceiveBytes(len, mReceiveByte.data); // KJLoger.debug("Read Length : " + len); Message msg = new Message(); //《疯狂》第210页 msg.what = 1; msg.obj = mReceiveByte.data; mHandler.sendMessage(msg); mReceiveByte.clear(); } else { //len != 35(在len>0里)即:0<len<35,并且35<len<128 if (mReceiveByte.length != 0) { //与上面作比较; System.arraycopy(rbuf, 0, mReceiveByte.data, mReceiveByte.length, len); //《J6》第64页 CheckReceiveBytes(len, mReceiveByte.data); //调用下面的函数 // KJLoger.debug("Read Length : " + len); Message msg = new Message(); //《疯狂》第210页 msg.what = 1; msg.obj = mReceiveByte.data; mHandler.sendMessage(msg); mReceiveByte.clear(); //调用下面的类的函数 } else { //mReceiveByte.length == 0 System.arraycopy(rbuf, 0, mReceiveByte.data, 0, len); //《J6》第64页 // Intent intent = new Intent(); //注意:怎么把Message转换为Intent // sendBroadcast(intent); } } } try { Thread.sleep(100); } catch (InterruptedException e) { //public void printStackTrace (): //Writes a printable representation of this Throwable's stack trace to the System.err stream. //写一个这个抛出堆栈的一个可打印的代表 到 系统错误流。 e.printStackTrace(); } if (mStop) { mRunningMainLoop = false; return; } } while (true); } //run()函数结束 在显示数据的主页ControlActivity2.java中的代码是: final Handler mHandler = new Handler() { int lenCtrl2; // ha = new HomeActivity(this); ObjectInputStream ois; @Override public void handleMessage(Message msg) { if (msg.what == 1) { ByteArrayInputStream bais = new ByteArrayInputStream((byte[]) msg.obj); try { ObjectInputStream ois = new ObjectInputStream(bais); } catch (StreamCorruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } do{ try { lenCtrl2 = (Integer) ois.readObject(); } catch (OptionalDataException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } if(lenCtrl2>0){ if(lenCtrl2 == 35){ System.arraycopy(ois, 0, rbufCtrl2.data, 0, 35); if(rbufCtrl2.data.length == 0) CheckReceiveBytes(lenCtrl2,rbufCtrl2.data); rbufCtrl2.clear(); }else{ if(rbufCtrl2.length!=0){ System.arraycopy(ois, 0, rbufCtrl2.data, 0, lenCtrl2); CheckReceiveBytes(lenCtrl2,rbufCtrl2.data); rbufCtrl2.clear(); }else{ System.arraycopy(ois, 0, rbufCtrl2.data, 0, lenCtrl2); //这个才是正常接收。 String str1 = Byte.toString(rbufCtrl2.data[18]); String str2 = Byte.toString(rbufCtrl2.data[19]); String str3 = Byte.toString(rbufCtrl2.data[20]); String str4 = Byte.toString(rbufCtrl2.data[24]); String str5 = Byte.toString(rbufCtrl2.data[25]); temperature_theindoor.setText(str1); temperature_theoutdoor.setText(str2); humidity_indoor.setText(str3); temperature_indoorintake.setText(str4); temperature_outdoorintake.setText(str5); } } } }while(true); // temperature_theindoor.setText((char[]) (msg.obj), 18, 1); // temperature_theoutdoor.setText((char[]) (msg.obj), 19, 1); // humidity_indoor.setText((char[]) (msg.obj), 20, 20); // temperature_indoorintake.setText((char[]) (msg.obj), 24, 1); // temperature_outdoorintake.setText((char[]) (msg.obj), 25, 1); } } private String IntToHex2(byte Value) { //被下面的函数调用 ;实际上就是Byte-->Char[](Character)16进制-->String char HEX2[] = { Character.forDigit((Value >> 4) & 0x0F, 16), Character.forDigit(Value & 0x0F, 16) }; String Hex2Str = new String(HEX2); return Hex2Str; } private void CheckReceiveBytes(int len, byte[] rbuf) { StringBuffer rr = new StringBuffer(); //《Java程序设计》第87页 rr.append(len + "\n"); rr.append(rbuf.length + "\n"); for (byte b : rbuf) { //foreach语句 rr.append(IntToHex2(b) + " "); //调用上面的函数 } Message msgtest = new Message(); msgtest.what = 77; //public int what Message类的域成员 msgtest.obj = rr.toString(); mHandler.sendMessage(msgtest); } } ; // 这里是new Handler()的结束 // Looper.loop(); // } // 这里是run()的结束 // } // } public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) { // TODO Auto-generated method stub } @Override public void mOnClickHeadMenu() { // TODO Auto-generated method stub } @Override public void mOnClickHeadBack() { // TODO Auto-generated method stub } @Override public void mOnClickHeadBack2() { // TODO Auto-generated method stub } } 但是这个程序编译出来之后,接到空调机里面还是接收不到数据,求解答。 以下页面是我要显示页面的图片: ![图片说明](https://img-ask.csdn.net/upload/201511/12/1447309029_191875.png)
Android 中new ObjectInputStream无法创建对象
``` //程序在这里报错了; this.ois = new ObjectInputStream(this.socket.getInputStream()); 程序报错说空指针异常,表面上看是下面的第二条语句in在调用方法时出错的,实际上是Client.getInstance().getClientInputThread()返回了空对象,也即是ClientInputThread构造方法中的 this.ois = new ObjectInputStream(this.socket.getInputStream()); 未能成功创建ois对象 这在后面打印出来的log信息也可以看出来。打印信息显示ois == null是 true,而oos == null 是 false; 事故语句块之语句1 final ClientInputThread in = Client.getInstance().getClientInputThread(); 事故语句块之语句2 in.setMessageListener(new MsgListener(...){}); ``` ``` //输入线程 public class ClientInputThread extends Thread { @SuppressWarnings("unused") private Socket socket; private ObjectInputStream ois; private TransEntity transEn; private MsgListener msgListener; private boolean isStart = true; public ClientInputThread(Socket socket) { this.socket = socket; try { this.ois = new ObjectInputStream(this.socket.getInputStream()); } catch (StreamCorruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public TransEntity getMsg() { if(transEn!=null) { synchronized (this) { try { wait(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } return transEn; } return null; } public void setMessageListener(MsgListener msgListener) { this.msgListener = msgListener; } public void releaseResource() { try { ois.close(); socket.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void run() { while(isStart) { //if(ois == null) System.out.println("ois == null : "+(ois == null)); try { transEn = (TransEntity) ois.readObject(); if(transEn!=null) { synchronized (this) { notify(); } } // msgListener.Message(transEn); } catch (OptionalDataException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClassNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } releaseResource(); } } ``` ``` //输出线程 public class OutputThread extends Thread { private Socket socket; private OutputThread outputThread; private ObjectOutputStream oos; private TransEntity transEn; private boolean isStart = true; public OutputThread(Socket socket) { this.socket = socket; try { oos = new ObjectOutputStream(socket.getOutputStream()); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } // 设置了消息之后,唤醒写线程 public void setMessage(TransEntity transEn) { this.transEn = transEn; synchronized (this) { notify(); } } public void releaseResouce() { try { if (oos != null) oos.close(); if (socket != null) socket.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public void run() { while(isStart) { synchronized (this) { try { if (transEn != null) { wait(); try { oos.writeObject(transEn); oos.flush(); //oos.reset(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } releaseResouce(); } } ``` ``` //客户端线程,在客户端线程启动输出和输入线程 public class ClientThread extends Thread { private ClientOutputThread out; private ClientInputThread in; private Socket socket; public ClientThread(Socket socket) { this.socket = socket; } public void run() { out = new ClientOutputThread(socket); in = new ClientInputThread(socket); out.start(); in.start(); } public ClientInputThread getIn() { return in; } public ClientOutputThread getOut() { return out; } } ``` ``` //客户端 public class Client { private static Client client; // private boolean isLogin = false; private Socket socket; private ClientThread clientThread; private Client() { } public static synchronized Client getInstance() { if (client == null) { client = new Client(); } return client; } public boolean startClient() { try { socket = new Socket(); socket.connect(new InetSocketAddress("10.0.2.2",5345),2000); if (socket.isConnected()) { System.out.println("Connecting..."); clientThread = new ClientThread(socket); clientThread.start(); } } catch (IOException e) { e.printStackTrace(); return false; } return true; } // 直接通过client得到读线程 public ClientInputThread getClientInputThread() { return clientThread.getIn(); } // 直接通过client得到写线程 public ClientOutputThread getClientOutputThread() { return clientThread.getOut(); } } ``` ``` //在onResume里头启动service,由service启动客户端 protected void onResume() { // TODO Auto-generated method stub super.onResume(); if (!GetMsgService.isStart) { Intent service = new Intent(FirstActivity.this, GetMsgService.class); startService(service); //isServiceRunning = true; } } ``` 报错信息 ![报错信息说是空指针异常经过检查得知是ClinetInputThread的构造方法中的this.ois对象为成功创建,所以后来在通过Client的getClientInputThread方法得到的是一个空对象](https://img-ask.csdn.net/upload/201604/30/1462014016_30077.png) ![但是ClientOutputThread中却能成功创建this.oos对象,如打印出的log信息显示,oos == true 是false](https://img-ask.csdn.net/upload/201604/30/1462014247_359151.png) ![ClientInputThread未能成功创建this.ois对象,如打印出的log信息显示,ois == true是 true](https://img-ask.csdn.net/upload/201604/30/1462014328_357949.png)
爬虫福利二 之 妹子图网MM批量下载
爬虫福利一:27报网MM批量下载 点击 看了本文,相信大家对爬虫一定会产生强烈的兴趣,激励自己去学习爬虫,在这里提前祝:大家学有所成! 目标网站:妹子图网 环境:Python3.x 相关第三方模块:requests、beautifulsoup4 Re:各位在测试时只需要将代码里的变量path 指定为你当前系统要保存的路径,使用 python xxx.py 或IDE运行即可。 ...
字节跳动视频编解码面经
三四月份投了字节跳动的实习(图形图像岗位),然后hr打电话过来问了一下会不会opengl,c++,shador,当时只会一点c++,其他两个都不会,也就直接被拒了。 七月初内推了字节跳动的提前批,因为内推没有具体的岗位,hr又打电话问要不要考虑一下图形图像岗,我说实习投过这个岗位不合适,不会opengl和shador,然后hr就说秋招更看重基础。我当时想着能进去就不错了,管他哪个岗呢,就同意了面试...
Java学习的正确打开方式
在博主认为,对于入门级学习java的最佳学习方法莫过于视频+博客+书籍+总结,前三者博主将淋漓尽致地挥毫于这篇博客文章中,至于总结在于个人,实际上越到后面你会发现学习的最好方式就是阅读参考官方文档其次就是国内的书籍,博客次之,这又是一个层次了,这里暂时不提后面再谈。博主将为各位入门java保驾护航,各位只管冲鸭!!!上天是公平的,只要不辜负时间,时间自然不会辜负你。 何谓学习?博主所理解的学习,它是一个过程,是一个不断累积、不断沉淀、不断总结、善于传达自己的个人见解以及乐于分享的过程。
程序员必须掌握的核心算法有哪些?
由于我之前一直强调数据结构以及算法学习的重要性,所以就有一些读者经常问我,数据结构与算法应该要学习到哪个程度呢?,说实话,这个问题我不知道要怎么回答你,主要取决于你想学习到哪些程度,不过针对这个问题,我稍微总结一下我学过的算法知识点,以及我觉得值得学习的算法。这些算法与数据结构的学习大多数是零散的,并没有一本把他们全部覆盖的书籍。下面是我觉得值得学习的一些算法以及数据结构,当然,我也会整理一些看过...
linux系列之常用运维命令整理笔录
本博客记录工作中需要的linux运维命令,大学时候开始接触linux,会一些基本操作,可是都没有整理起来,加上是做开发,不做运维,有些命令忘记了,所以现在整理成博客,当然vi,文件操作等就不介绍了,慢慢积累一些其它拓展的命令,博客不定时更新 free -m 其中:m表示兆,也可以用g,注意都要小写 Men:表示物理内存统计 total:表示物理内存总数(total=used+free) use...
Python 基础(一):入门必备知识
Python 入门必备知识,你都掌握了吗?
兼职程序员一般可以从什么平台接私活?
这个问题我进行了系统性的总结,以下将进行言简意赅的说明和渠道提供,希望对各位小猿/小媛们有帮助~ 根据我们的经验,程序员兼职主要分为三种:兼职职位众包、项目整包和自由职业者驻场。 所谓的兼职职位众包,指的是需求方这边有自有工程师配合,只需要某个职位的工程师开发某个模块的项目。比如开发一个 app,后端接口有人开发,但是缺少 iOS 前端开发工程师,那么他们就会发布一个职位招聘前端,来配合公司一...
程序员接私活怎样防止做完了不给钱?
首先跟大家说明一点,我们做 IT 类的外包开发,是非标品开发,所以很有可能在开发过程中会有这样那样的需求修改,而这种需求修改很容易造成扯皮,进而影响到费用支付,甚至出现做完了项目收不到钱的情况。 那么,怎么保证自己的薪酬安全呢? 我们在开工前,一定要做好一些证据方面的准备(也就是“讨薪”的理论依据),这其中最重要的就是需求文档和验收标准。一定要让需求方提供这两个文档资料作为开发的基础。之后开发...
Python十大装B语法
Python 是一种代表简单思想的语言,其语法相对简单,很容易上手。不过,如果就此小视 Python 语法的精妙和深邃,那就大错特错了。本文精心筛选了最能展现 Python 语法之精妙的十个知识点,并附上详细的实例代码。如能在实战中融会贯通、灵活使用,必将使代码更为精炼、高效,同时也会极大提升代码B格,使之看上去更老练,读起来更优雅。
数据库优化 - SQL优化
以实际SQL入手,带你一步一步走上SQL优化之路!
2019年11月中国大陆编程语言排行榜
2019年11月2日,我统计了某招聘网站,获得有效程序员招聘数据9万条。针对招聘信息,提取编程语言关键字,并统计如下: 编程语言比例 rank pl_ percentage 1 java 33.62% 2 cpp 16.42% 3 c_sharp 12.82% 4 javascript 12.31% 5 python 7.93% 6 go 7.25% 7 p...
写了很久,这是一份最适合/贴切普通大众/科班/非科班的『学习路线』
说实话,对于学习路线这种文章我一般是不写的,大家看我的文章也知道,我是很少写建议别人怎么样怎么样的文章,更多的是,写自己的真实经历,然后供大家去参考,这样子,我内心也比较踏实,也不怕误导他人。 但是,最近好多人问我学习路线,而且很多大一大二的,说自己很迷茫,看到我那篇 普普通通,我的三年大学 之后很受激励,觉得自己也能行,(是的,别太浪,你一定能行)希望我能给他个学习路线,说...
经典算法(5)杨辉三角
写在前面: 我是 扬帆向海,这个昵称来源于我的名字以及女朋友的名字。我热爱技术、热爱开源、热爱编程。技术是开源的、知识是共享的。 这博客是对自己学习的一点点总结及记录,如果您对 Java、算法 感兴趣,可以关注我的动态,我们一起学习。 用知识改变命运,让我们的家人过上更好的生活。 目录一、杨辉三角的介绍二、杨辉三角的算法思想三、代码实现1.第一种写法2.第二种写法 一、杨辉三角的介绍 百度
腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹?
昨天,有网友私信我,说去阿里面试,彻底的被打击到了。问了为什么网上大量使用ThreadLocal的源码都会加上private static?他被难住了,因为他从来都没有考虑过这个问题。无独有偶,今天笔者又发现有网友吐槽了一道腾讯的面试题,我们一起来看看。 腾讯算法面试题:64匹马8个跑道需要多少轮才能选出最快的四匹? 在互联网职场论坛,一名程序员发帖求助到。二面腾讯,其中一个算法题:64匹...
面试官:你连RESTful都不知道我怎么敢要你?
干货,2019 RESTful最贱实践
为啥国人偏爱Mybatis,而老外喜欢Hibernate/JPA呢?
关于SQL和ORM的争论,永远都不会终止,我也一直在思考这个问题。昨天又跟群里的小伙伴进行了一番讨论,感触还是有一些,于是就有了今天这篇文。 声明:本文不会下关于Mybatis和JPA两个持久层框架哪个更好这样的结论。只是摆事实,讲道理,所以,请各位看官勿喷。 一、事件起因 关于Mybatis和JPA孰优孰劣的问题,争论已经很多年了。一直也没有结论,毕竟每个人的喜好和习惯是大不相同的。我也看...
SQL-小白最佳入门sql查询一
不要偷偷的查询我的个人资料,即使你再喜欢我,也不要这样,真的不好;
项目中的if else太多了,该怎么重构?
介绍 最近跟着公司的大佬开发了一款IM系统,类似QQ和微信哈,就是聊天软件。我们有一部分业务逻辑是这样的 if (msgType = "文本") { // dosomething } else if(msgType = "图片") { // doshomething } else if(msgType = "视频") { // doshomething } else { // doshom...
致 Python 初学者
欢迎来到“Python进阶”专栏!来到这里的每一位同学,应该大致上学习了很多 Python 的基础知识,正在努力成长的过程中。在此期间,一定遇到了很多的困惑,对未来的学习方向感到迷茫。我非常理解你们所面临的处境。我从2007年开始接触 python 这门编程语言,从2009年开始单一使用 python 应对所有的开发工作,直至今天。回顾自己的学习过程,也曾经遇到过无数的困难,也曾经迷茫过、困惑过。开办这个专栏,正是为了帮助像我当年一样困惑的 Python 初学者走出困境、快速成长。希望我的经验能真正帮到你
“狗屁不通文章生成器”登顶GitHub热榜,分分钟写出万字形式主义大作
一、垃圾文字生成器介绍 最近在浏览GitHub的时候,发现了这样一个骨骼清奇的雷人项目,而且热度还特别高。 项目中文名:狗屁不通文章生成器 项目英文名:BullshitGenerator 根据作者的介绍,他是偶尔需要一些中文文字用于GUI开发时测试文本渲染,因此开发了这个废话生成器。但由于生成的废话实在是太过富于哲理,所以最近已经被小伙伴们给玩坏了。 他的文风可能是这样的: 你发现,
程序员:我终于知道post和get的区别
IT界知名的程序员曾说:对于那些月薪三万以下,自称IT工程师的码农们,其实我们从来没有把他们归为我们IT工程师的队伍。他们虽然总是以IT工程师自居,但只是他们一厢情愿罢了。 此话一出,不知激起了多少(码农)程序员的愤怒,却又无可奈何,于是码农问程序员。 码农:你知道get和post请求到底有什么区别? 程序员:你看这篇就知道了。 码农:你月薪三万了? 程序员:嗯。 码农:你是怎么做到的? 程序员:
《程序人生》系列-这个程序员只用了20行代码就拿了冠军
你知道的越多,你不知道的越多 点赞再看,养成习惯GitHub上已经开源https://github.com/JavaFamily,有一线大厂面试点脑图,欢迎Star和完善 前言 这一期不算《吊打面试官》系列的,所有没前言我直接开始。 絮叨 本来应该是没有这期的,看过我上期的小伙伴应该是知道的嘛,双十一比较忙嘛,要值班又要去帮忙拍摄年会的视频素材,还得搞个程序员一天的Vlog,还要写BU
加快推动区块链技术和产业创新发展,2019可信区块链峰会在京召开
11月8日,由中国信息通信研究院、中国通信标准化协会、中国互联网协会、可信区块链推进计划联合主办,科技行者协办的2019可信区块链峰会将在北京悠唐皇冠假日酒店开幕。   区块链技术被认为是继蒸汽机、电力、互联网之后,下一代颠覆性的核心技术。如果说蒸汽机释放了人类的生产力,电力解决了人类基本的生活需求,互联网彻底改变了信息传递的方式,区块链作为构造信任的技术有重要的价值。   1...
程序员把地府后台管理系统做出来了,还有3.0版本!12月7号最新消息:已在开发中有github地址
第一幕:缘起 听说阎王爷要做个生死簿后台管理系统,我们派去了一个程序员…… 996程序员做的梦: 第一场:团队招募 为了应对地府管理危机,阎王打算找“人”开发一套地府后台管理系统,于是就在地府总经办群中发了项目需求。 话说还是中国电信的信号好,地府都是满格,哈哈!!! 经常会有外行朋友问:看某网站做的不错,功能也简单,你帮忙做一下? 而这次,面对这样的需求,这个程序员
网易云6亿用户音乐推荐算法
网易云音乐是音乐爱好者的集聚地,云音乐推荐系统致力于通过 AI 算法的落地,实现用户千人千面的个性化推荐,为用户带来不一样的听歌体验。 本次分享重点介绍 AI 算法在音乐推荐中的应用实践,以及在算法落地过程中遇到的挑战和解决方案。 将从如下两个部分展开: AI 算法在音乐推荐中的应用 音乐场景下的 AI 思考 从 2013 年 4 月正式上线至今,网易云音乐平台持续提供着:乐屏社区、UGC
8年经验面试官详解 Java 面试秘诀
    作者 | 胡书敏 责编 | 刘静 出品 | CSDN(ID:CSDNnews) 本人目前在一家知名外企担任架构师,而且最近八年来,在多家外企和互联网公司担任Java技术面试官,前后累计面试了有两三百位候选人。在本文里,就将结合本人的面试经验,针对Java初学者、Java初级开发和Java开发,给出若干准备简历和准备面试的建议。   Java程序员准备和投递简历的实
面试官如何考察你的思维方式?
1.两种思维方式在求职面试中,经常会考察这种问题:北京有多少量特斯拉汽车? 某胡同口的煎饼摊一年能卖出多少个煎饼? 深圳有多少个产品经理? 一辆公交车里能装下多少个乒乓球? 一
碎片化的时代,如何学习
今天周末,和大家聊聊学习这件事情。 在如今这个社会,我们的时间被各类 APP 撕的粉碎。 刷知乎、刷微博、刷朋友圈; 看论坛、看博客、看公号; 等等形形色色的信息和知识获取方式一个都不错过。 貌似学了很多,但是却感觉没什么用。 要解决上面这些问题,首先要分清楚一点,什么是信息,什么是知识。 那什么是信息呢? 你一切听到的、看到的,都是信息,比如微博上的明星出轨、微信中的表情大战、抖音上的...
so easy! 10行代码写个"狗屁不通"文章生成器
前几天,GitHub 有个开源项目特别火,只要输入标题就可以生成一篇长长的文章。 背后实现代码一定很复杂吧,里面一定有很多高深莫测的机器学习等复杂算法 不过,当我看了源代码之后 这程序不到50行 尽管我有多年的Python经验,但我竟然一时也没有看懂 当然啦,原作者也说了,这个代码也是在无聊中诞生的,平时撸码是不写中文变量名的, 中文...
知乎高赞:中国有什么拿得出手的开源软件产品?(整理自本人原创回答)
知乎高赞:中国有什么拿得出手的开源软件产品? 在知乎上,有个问题问“中国有什么拿得出手的开源软件产品(在 GitHub 等社区受欢迎度较好的)?” 事实上,还不少呢~ 本人于2019.7.6进行了较为全面的回答,对这些受欢迎的 Github 开源项目分类整理如下: 分布式计算、云平台相关工具类 1.SkyWalking,作者吴晟、刘浩杨 等等 仓库地址: apache/skywalking 更...
相关热词 c#处理浮点数 c# 生成字母数字随机数 c# 动态曲线 控件 c# oracle 开发 c#选择字体大小的控件 c# usb 批量传输 c#10进制转8进制 c#转base64 c# 科学计算 c#下拉列表获取串口
立即提问