View | Details | Raw Unified | Return to bug 44898
Collapse All | Expand All

(-)src/java/org/apache/poi/poifs/storage/RawDataBlock.java (-4 / +3 lines)
Lines 72-81 Link Here
72
            _eof = true;
72
            _eof = true;
73
        }
73
        }
74
        else if (count != blockSize) {
74
        else if (count != blockSize) {
75
        	// IOUtils.readFully will always read the
75
            // IOUtils.readFully will always read the requested number
76
        	//  requested number of bytes, unless it hits
76
            // of bytes unless it hits EOF.
77
        	//  an EOF
77
            // Original code set _eof = true here, but this causes "Cannot remove block" errors later.
78
            _eof = true;
79
            String type = " byte" + ((count == 1) ? ("")
78
            String type = " byte" + ((count == 1) ? ("")
80
                                                  : ("s"));
79
                                                  : ("s"));
81
80
(-)src/testcases/org/apache/poi/poifs/storage/TestRawDataBlockList.java (-9 / +5 lines)
Lines 76-84 Link Here
76
76
77
    /**
77
    /**
78
     * Test creating a short RawDataBlockList
78
     * Test creating a short RawDataBlockList
79
     *
80
     * @exception IOException
79
     */
81
     */
80
82
81
    public void testShortConstructor()
83
    public void testShortConstructor()
84
        throws IOException
82
    {
85
    {
83
        for (int k = 2049; k < 2560; k++)
86
        for (int k = 2049; k < 2560; k++)
84
        {
87
        {
Lines 88-103 Link Here
88
            {
91
            {
89
                data[ j ] = ( byte ) j;
92
                data[ j ] = ( byte ) j;
90
            }
93
            }
91
            try
92
            {
93
                new RawDataBlockList(new ByteArrayInputStream(data));
94
                fail("Should have thrown IOException creating short block");
95
            }
96
            catch (IOException ignored)
97
            {
98
94
99
                // as expected
95
            // Should not throw IOException creating short block
100
            }
96
            new RawDataBlockList(new ByteArrayInputStream(data));
101
        }
97
        }
102
    }
98
    }
103
99
(-)src/testcases/org/apache/poi/poifs/storage/TestRawDataBlock.java (-20 / +11 lines)
Lines 99-107 Link Here
99
99
100
    /**
100
    /**
101
     * Test creating a short RawDataBlock
101
     * Test creating a short RawDataBlock
102
     *
103
     * @exception IOException
102
     */
104
     */
103
105
104
    public void testShortConstructor()
106
    public void testShortConstructor()
107
        throws IOException
105
    {
108
    {
106
        for (int k = 1; k < 512; k++)
109
        for (int k = 1; k < 512; k++)
107
        {
110
        {
Lines 111-128 Link Here
111
            {
114
            {
112
                data[ j ] = ( byte ) j;
115
                data[ j ] = ( byte ) j;
113
            }
116
            }
114
            RawDataBlock block = null;
115
117
116
            try
118
            // Should not be EOF and thus not throw IOException getting the data.
117
            {
119
            RawDataBlock block = new RawDataBlock(new ByteArrayInputStream(data));
118
                block = new RawDataBlock(new ByteArrayInputStream(data));
120
            assertFalse("Should not be EOF", block.eof());
119
                fail("Should have thrown IOException creating short block");
121
            block.getData();
120
            }
121
            catch (IOException ignored)
122
            {
123
124
                // as expected
125
            }
126
        }
122
        }
127
    }
123
    }
128
    
124
    
Lines 145-152 Link Here
145
            assertFalse(block.eof());
141
            assertFalse(block.eof());
146
        }
142
        }
147
        
143
        
148
        // But if there wasn't enough data available, will
144
        // If there wasn't enough data available, will not complain but will read partially.
149
        //  complain
150
        for (int k = 1; k < 512; k++) {
145
        for (int k = 1; k < 512; k++) {
151
            byte[] data = new byte[ 511 ];
146
            byte[] data = new byte[ 511 ];
152
            for (int j = 0; j < data.length; j++) {
147
            for (int j = 0; j < data.length; j++) {
Lines 154-166 Link Here
154
            }
149
            }
155
            
150
            
156
            // Shouldn't complain, as there is enough data
151
            // Shouldn't complain, as there is enough data
157
            try {
152
            RawDataBlock block = 
158
	            RawDataBlock block = 
153
                new RawDataBlock(new SlowInputStream(data, k));
159
	            	new RawDataBlock(new SlowInputStream(data, k));
154
            assertFalse(block.eof());
160
	            fail();
161
            } catch(IOException e) {
162
            	// as expected
163
            }
164
        }
155
        }
165
    }
156
    }
166
    
157
    

Return to bug 44898