src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/hpack/IntegerReader.java
equal
deleted
inserted
replaced
1 /* |
1 /* |
2 * Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. |
2 * Copyright (c) 2014, 2017, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
5 * This code is free software; you can redistribute it and/or modify it |
6 * under the terms of the GNU General Public License version 2 only, as |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. Oracle designates this |
7 * published by the Free Software Foundation. Oracle designates this |
22 * or visit www.oracle.com if you need additional information or have any |
22 * or visit www.oracle.com if you need additional information or have any |
23 * questions. |
23 * questions. |
24 */ |
24 */ |
25 package jdk.incubator.http.internal.hpack; |
25 package jdk.incubator.http.internal.hpack; |
26 |
26 |
|
27 import java.io.IOException; |
27 import java.nio.ByteBuffer; |
28 import java.nio.ByteBuffer; |
28 import java.util.Arrays; |
29 import java.util.Arrays; |
29 |
30 |
30 import static java.lang.String.format; |
31 import static java.lang.String.format; |
31 |
32 |
71 this.N = N; |
72 this.N = N; |
72 state = CONFIGURED; |
73 state = CONFIGURED; |
73 return this; |
74 return this; |
74 } |
75 } |
75 |
76 |
76 public boolean read(ByteBuffer input) { |
77 public boolean read(ByteBuffer input) throws IOException { |
77 if (state == NEW) { |
78 if (state == NEW) { |
78 throw new IllegalStateException("Configure first"); |
79 throw new IllegalStateException("Configure first"); |
79 } |
80 } |
80 if (state == DONE) { |
81 if (state == DONE) { |
81 return true; |
82 return true; |
103 return false; |
104 return false; |
104 } |
105 } |
105 i = input.get(); |
106 i = input.get(); |
106 long increment = b * (i & 127); |
107 long increment = b * (i & 127); |
107 if (r + increment > maxValue) { |
108 if (r + increment > maxValue) { |
108 throw new IllegalArgumentException(format( |
109 throw new IOException(format( |
109 "Integer overflow: maxValue=%,d, value=%,d", |
110 "Integer overflow: maxValue=%,d, value=%,d", |
110 maxValue, r + increment)); |
111 maxValue, r + increment)); |
111 } |
112 } |
112 r += increment; |
113 r += increment; |
113 b *= 128; |
114 b *= 128; |