• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apache / iotdb / #9986

04 Sep 2023 12:14AM UTC coverage: 47.705% (+0.003%) from 47.702%
#9986

push

travis_ci

web-flow
Fix possible NPE while executing show cluster or show cluster details

42 of 42 new or added lines in 2 files covered. (100.0%)

80193 of 168102 relevant lines covered (47.7%)

0.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

37.5
/iotdb-core/tsfile/src/main/java/org/apache/iotdb/tsfile/read/reader/LocalTsFileInput.java
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing,
13
 * software distributed under the License is distributed on an
14
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15
 * KIND, either express or implied.  See the License for the
16
 * specific language governing permissions and limitations
17
 * under the License.
18
 */
19

20
package org.apache.iotdb.tsfile.read.reader;
21

22
import org.slf4j.Logger;
23
import org.slf4j.LoggerFactory;
24

25
import java.io.IOException;
26
import java.io.InputStream;
27
import java.nio.ByteBuffer;
28
import java.nio.channels.Channels;
29
import java.nio.channels.ClosedByInterruptException;
30
import java.nio.channels.FileChannel;
31
import java.nio.file.Path;
32
import java.nio.file.StandardOpenOption;
33

34
public class LocalTsFileInput implements TsFileInput {
35

36
  private static final Logger logger = LoggerFactory.getLogger(LocalTsFileInput.class);
1✔
37

38
  private final FileChannel channel;
39
  private final String filePath;
40

41
  public LocalTsFileInput(Path file) throws IOException {
1✔
42
    channel = FileChannel.open(file, StandardOpenOption.READ);
1✔
43
    filePath = file.toString();
1✔
44
  }
1✔
45

46
  @Override
47
  public long size() throws IOException {
48
    try {
49
      return channel.size();
1✔
50
    } catch (IOException e) {
×
51
      logger.error("Error happened while getting {} size", filePath);
×
52
      throw e;
×
53
    }
54
  }
55

56
  @Override
57
  public long position() throws IOException {
58
    try {
59
      return channel.position();
1✔
60
    } catch (IOException e) {
×
61
      logger.error("Error happened while getting {} current position", filePath);
×
62
      throw e;
×
63
    }
64
  }
65

66
  @Override
67
  public TsFileInput position(long newPosition) throws IOException {
68
    try {
69
      channel.position(newPosition);
1✔
70
      return this;
1✔
71
    } catch (IOException e) {
×
72
      logger.error("Error happened while changing {} position to {}", filePath, newPosition);
×
73
      throw e;
×
74
    }
75
  }
76

77
  @Override
78
  public int read(ByteBuffer dst) throws IOException {
79
    try {
80
      return channel.read(dst);
1✔
81
    } catch (ClosedByInterruptException e) {
×
82
      logger.warn(
×
83
          "Current thread is interrupted by another thread when it is blocked in an I/O operation upon a channel.");
84
      return -1;
×
85
    } catch (IOException e) {
×
86
      logger.error("Error happened while reading {} from current position", filePath);
×
87
      throw e;
×
88
    }
89
  }
90

91
  @Override
92
  public int read(ByteBuffer dst, long position) throws IOException {
93
    try {
94
      return channel.read(dst, position);
1✔
95
    } catch (ClosedByInterruptException e) {
×
96
      logger.warn(
×
97
          "Current thread is interrupted by another thread when it is blocked in an I/O operation upon a channel.");
98
      return -1;
×
99
    } catch (IOException e) {
×
100
      logger.error("Error happened while reading {} from position {}", filePath, position);
×
101
      throw e;
×
102
    }
103
  }
104

105
  @Override
106
  public InputStream wrapAsInputStream() {
107
    return Channels.newInputStream(channel);
1✔
108
  }
109

110
  @Override
111
  public void close() throws IOException {
112
    try {
113
      channel.close();
1✔
114
    } catch (IOException e) {
×
115
      logger.error("Error happened while closing {}", filePath);
×
116
      throw e;
×
117
    }
1✔
118
  }
1✔
119

120
  @Override
121
  public String getFilePath() {
122
    return filePath;
×
123
  }
124
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc