Skip to content

Commit

Permalink
Merge branch 'develop' into devsecops
Browse files Browse the repository at this point in the history
  • Loading branch information
aleks-ivanov committed Jun 11, 2024
2 parents a321c24 + 288dd41 commit 4bcfd64
Show file tree
Hide file tree
Showing 135 changed files with 1,167 additions and 1,339 deletions.
426 changes: 168 additions & 258 deletions itext.tests/itext.forms.tests/itext/forms/XfdfReaderTest.cs

Large diffs are not rendered by default.

226 changes: 113 additions & 113 deletions itext.tests/itext.forms.tests/itext/forms/XfdfWriterTest.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.IO;
using iText.Commons.Utils;
using iText.Kernel.Colors;
using iText.Kernel.Pdf;
using iText.Kernel.Utils;
Expand Down Expand Up @@ -59,7 +59,7 @@ public virtual void ButtonsWithoutColorTest() {
}

private static void DrawButtons(String outPdf, String cmpPdf, Color color) {
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(new FileStream(outPdf, FileMode.Create)))) {
using (PdfDocument pdfDocument = new PdfDocument(new PdfWriter(FileUtil.GetFileOutputStream(outPdf)))) {
using (Document document = new Document(pdfDocument)) {
Button button = new Button("button");
button.Add(new Paragraph("button child paragraph"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
using System;
using System.IO;
using iText.Commons.Utils;
using iText.Forms;
using iText.Forms.Fields;
using iText.Forms.Fields.Borders;
Expand Down Expand Up @@ -177,8 +177,8 @@ public virtual void AddButtonInTwoWaysTest() {
formButton.SetProperty(FormProperty.FORM_FIELD_FLATTEN, false);
formButton.SetProperty(Property.WIDTH, UnitValue.CreatePointValue(100));
formButton.SetProperty(Property.HEIGHT, UnitValue.CreatePointValue(100));
formButton.Add(new Image(new PdfImageXObject(ImageDataFactory.Create(StreamUtil.InputStreamToArray(new FileStream
(imagePath, FileMode.Open, FileAccess.Read))))).SetWidth(98).SetHeight(98));
formButton.Add(new Image(new PdfImageXObject(ImageDataFactory.Create(StreamUtil.InputStreamToArray(FileUtil
.GetInputStreamForFile(imagePath))))).SetWidth(98).SetHeight(98));
formButton.SetFontColor(ColorConstants.BLUE);
formButton.SetBackgroundColor(ColorConstants.YELLOW);
formButton.SetBorder(new SolidBorder(ColorConstants.GREEN, 1));
Expand Down
3 changes: 2 additions & 1 deletion itext.tests/itext.forms.tests/itext/forms/xfa/XFAFormTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ You should have received a copy of the GNU Affero General Public License
using System.IO;
using System.Xml;
using System.Xml.Linq;
using iText.Commons.Utils;
using iText.Forms;
using iText.Forms.Fields;
using iText.Kernel.Pdf;
Expand Down Expand Up @@ -77,7 +78,7 @@ public virtual void CreateXFAFormTest() {
String outFileName = destinationFolder + "createXFAFormTest.pdf";
String cmpFileName = sourceFolder + "cmp_createXFAFormTest.pdf";
PdfDocument doc = new PdfDocument(new PdfWriter(outFileName));
XfaForm xfa = new XfaForm(new FileStream(XML, FileMode.Open, FileAccess.Read));
XfaForm xfa = new XfaForm(FileUtil.GetInputStreamForFile(XML));
xfa.Write(doc);
doc.AddNewPage();
doc.Close();
Expand Down
33 changes: 16 additions & 17 deletions itext.tests/itext.io.tests/itext/io/font/otf/GlyphLineTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ You should have received a copy of the GNU Affero General Public License
*/
using System;
using System.Collections.Generic;
using System.IO;
using iText.Commons.Utils;
using iText.IO.Font;
using iText.IO.Util;
Expand Down Expand Up @@ -57,8 +56,8 @@ public virtual void TestEquals() {

[NUnit.Framework.Test]
public virtual void TestOtherLinesAddition() {
byte[] ttf = StreamUtil.InputStreamToArray(new FileStream(iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/io/font/otf/FreeSans.ttf", FileMode.Open, FileAccess.Read
byte[] ttf = StreamUtil.InputStreamToArray(FileUtil.GetInputStreamForFile(iText.Test.TestUtil.GetParentProjectDirectory
(NUnit.Framework.TestContext.CurrentContext.TestDirectory) + "/resources/itext/io/font/otf/FreeSans.ttf"
));
TrueTypeFont font = new TrueTypeFont(ttf);
GlyphLine containerLine = new GlyphLine(ConstructGlyphListFromString("Viva France!", font));
Expand All @@ -81,8 +80,8 @@ public virtual void TestOtherLinesAddition() {

[NUnit.Framework.Test]
public virtual void TestAdditionWithActualText() {
byte[] ttf = StreamUtil.InputStreamToArray(new FileStream(iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/io/font/otf/FreeSans.ttf", FileMode.Open, FileAccess.Read
byte[] ttf = StreamUtil.InputStreamToArray(FileUtil.GetInputStreamForFile(iText.Test.TestUtil.GetParentProjectDirectory
(NUnit.Framework.TestContext.CurrentContext.TestDirectory) + "/resources/itext/io/font/otf/FreeSans.ttf"
));
TrueTypeFont font = new TrueTypeFont(ttf);
IList<Glyph> glyphs = ConstructGlyphListFromString("Viva France!", font);
Expand All @@ -101,8 +100,8 @@ public virtual void TestAdditionWithActualText() {

[NUnit.Framework.Test]
public virtual void TestOtherLinesWithActualTextAddition() {
byte[] ttf = StreamUtil.InputStreamToArray(new FileStream(iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/io/font/otf/FreeSans.ttf", FileMode.Open, FileAccess.Read
byte[] ttf = StreamUtil.InputStreamToArray(FileUtil.GetInputStreamForFile(iText.Test.TestUtil.GetParentProjectDirectory
(NUnit.Framework.TestContext.CurrentContext.TestDirectory) + "/resources/itext/io/font/otf/FreeSans.ttf"
));
TrueTypeFont font = new TrueTypeFont(ttf);
GlyphLine containerLine = new GlyphLine(ConstructGlyphListFromString("France", font));
Expand All @@ -121,8 +120,8 @@ public virtual void TestOtherLinesWithActualTextAddition() {

[NUnit.Framework.Test]
public virtual void TestOtherLinesWithActualTextAddition02() {
byte[] ttf = StreamUtil.InputStreamToArray(new FileStream(iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/io/font/otf/FreeSans.ttf", FileMode.Open, FileAccess.Read
byte[] ttf = StreamUtil.InputStreamToArray(FileUtil.GetInputStreamForFile(iText.Test.TestUtil.GetParentProjectDirectory
(NUnit.Framework.TestContext.CurrentContext.TestDirectory) + "/resources/itext/io/font/otf/FreeSans.ttf"
));
TrueTypeFont font = new TrueTypeFont(ttf);
GlyphLine containerLine = new GlyphLine(ConstructGlyphListFromString("France", font));
Expand All @@ -146,8 +145,8 @@ public virtual void TestOtherLinesWithActualTextAddition02() {

[NUnit.Framework.Test]
public virtual void TestContentReplacingWithNullActualText() {
byte[] ttf = StreamUtil.InputStreamToArray(new FileStream(iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/io/font/otf/FreeSans.ttf", FileMode.Open, FileAccess.Read
byte[] ttf = StreamUtil.InputStreamToArray(FileUtil.GetInputStreamForFile(iText.Test.TestUtil.GetParentProjectDirectory
(NUnit.Framework.TestContext.CurrentContext.TestDirectory) + "/resources/itext/io/font/otf/FreeSans.ttf"
));
TrueTypeFont font = new TrueTypeFont(ttf);
GlyphLine lineToBeReplaced = new GlyphLine(ConstructGlyphListFromString("Byelorussia", font));
Expand All @@ -162,8 +161,8 @@ public virtual void TestContentReplacingWithNullActualText() {
public virtual void TestActualTextForSubstitutedGlyphProcessingInSubstituteOneToMany01() {
String expectedActualTextForFirstGlyph = "0";
String expectedActualTextForSecondGlyph = "A";
byte[] ttf = StreamUtil.InputStreamToArray(new FileStream(iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/io/font/otf/FreeSans.ttf", FileMode.Open, FileAccess.Read
byte[] ttf = StreamUtil.InputStreamToArray(FileUtil.GetInputStreamForFile(iText.Test.TestUtil.GetParentProjectDirectory
(NUnit.Framework.TestContext.CurrentContext.TestDirectory) + "/resources/itext/io/font/otf/FreeSans.ttf"
));
TrueTypeFont font = new TrueTypeFont(ttf);
// no actual text for the second glyph is set - it should be created during substitution
Expand All @@ -182,8 +181,8 @@ public virtual void TestActualTextForSubstitutedGlyphProcessingInSubstituteOneTo
[NUnit.Framework.Test]
public virtual void TestActualTextForSubstitutedGlyphProcessingInSubstituteOneToMany02() {
String expectedActualTextForFirstGlyph = "A";
byte[] ttf = StreamUtil.InputStreamToArray(new FileStream(iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/io/font/otf/FreeSans.ttf", FileMode.Open, FileAccess.Read
byte[] ttf = StreamUtil.InputStreamToArray(FileUtil.GetInputStreamForFile(iText.Test.TestUtil.GetParentProjectDirectory
(NUnit.Framework.TestContext.CurrentContext.TestDirectory) + "/resources/itext/io/font/otf/FreeSans.ttf"
));
TrueTypeFont font = new TrueTypeFont(ttf);
GlyphLine line = new GlyphLine(ConstructGlyphListFromString("A", font));
Expand All @@ -197,8 +196,8 @@ public virtual void TestActualTextForSubstitutedGlyphProcessingInSubstituteOneTo

[NUnit.Framework.Test]
public virtual void TestActualTextForSubstitutedGlyphProcessingInSubstituteOneToMany03() {
byte[] ttf = StreamUtil.InputStreamToArray(new FileStream(iText.Test.TestUtil.GetParentProjectDirectory(NUnit.Framework.TestContext
.CurrentContext.TestDirectory) + "/resources/itext/io/font/otf/FreeSans.ttf", FileMode.Open, FileAccess.Read
byte[] ttf = StreamUtil.InputStreamToArray(FileUtil.GetInputStreamForFile(iText.Test.TestUtil.GetParentProjectDirectory
(NUnit.Framework.TestContext.CurrentContext.TestDirectory) + "/resources/itext/io/font/otf/FreeSans.ttf"
));
TrueTypeFont font = new TrueTypeFont(ttf);
// no actual text is set
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ You should have received a copy of the GNU Affero General Public License
*/
using System;
using System.IO;
using iText.Commons.Utils;
using iText.IO.Exceptions;
using iText.Test;

Expand Down Expand Up @@ -68,7 +69,7 @@ protected internal void RunTest(String fileName, String sourceFolder, String tar

protected internal void SaveFile(byte[] content, String fileName) {
if (content != null) {
Stream os = new FileStream(fileName, FileMode.Create);
Stream os = FileUtil.GetFileOutputStream(fileName);
os.Write(content);
os.Dispose();
}
Expand Down
3 changes: 2 additions & 1 deletion itext.tests/itext.io.tests/itext/io/image/BmpTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ You should have received a copy of the GNU Affero General Public License
*/
using System;
using System.IO;
using iText.Commons.Utils;
using iText.IO.Util;
using iText.Test;

Expand Down Expand Up @@ -52,7 +53,7 @@ public virtual void OpenBmp2() {
[NUnit.Framework.Test]
public virtual void OpenBmp3() {
String imageFileName = sourceFolder + "WP_20140410_001_monochrome.bmp";
using (FileStream fis = new FileStream(imageFileName, FileMode.Open, FileAccess.Read)) {
using (Stream fis = FileUtil.GetInputStreamForFile(imageFileName)) {
byte[] imageBytes = StreamUtil.InputStreamToArray(fis);
// Test this a more specific entry point
ImageData img = ImageDataFactory.CreateBmp(imageBytes, false);
Expand Down
7 changes: 3 additions & 4 deletions itext.tests/itext.io.tests/itext/io/image/GifTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ public class GifTest : ExtendedITextTest {

[NUnit.Framework.Test]
public virtual void GifImageTest() {
using (FileStream file = new FileStream(sourceFolder + "WP_20140410_001.gif", FileMode.Open, FileAccess.Read
)) {
using (Stream file = FileUtil.GetInputStreamForFile(sourceFolder + "WP_20140410_001.gif")) {
byte[] fileContent = StreamUtil.InputStreamToArray(file);
ImageData img = ImageDataFactory.CreateGif(fileContent).GetFrames()[0];
NUnit.Framework.Assert.IsTrue(img.IsRawImage());
Expand All @@ -56,7 +55,7 @@ public virtual void GifImageFrameOutOfBoundsTest() {
[NUnit.Framework.Test]
public virtual void GifImageSpecificFrameTest() {
String imageFilePath = sourceFolder + "image-2frames.gif";
using (FileStream file = new FileStream(imageFilePath, FileMode.Open, FileAccess.Read)) {
using (Stream file = FileUtil.GetInputStreamForFile(imageFilePath)) {
byte[] fileContent = StreamUtil.InputStreamToArray(file);
ImageData img = ImageDataFactory.CreateGifFrame(fileContent, 2);
NUnit.Framework.Assert.AreEqual(100, (int)img.GetWidth());
Expand All @@ -69,7 +68,7 @@ public virtual void GifImageSpecificFrameTest() {
[NUnit.Framework.Test]
public virtual void GifImageReadingAllFramesTest() {
String imageFilePath = sourceFolder + "image-2frames.gif";
using (FileStream file = new FileStream(imageFilePath, FileMode.Open, FileAccess.Read)) {
using (Stream file = FileUtil.GetInputStreamForFile(imageFilePath)) {
byte[] fileContent = StreamUtil.InputStreamToArray(file);
IList<ImageData> frames = ImageDataFactory.CreateGifFrames(fileContent);
NUnit.Framework.Assert.AreEqual(2, frames.Count);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public virtual void TestImageTypeSupportWmfType() {

private void TestImageTypeSupport(Uri location, bool expectedResult) {
NUnit.Framework.Assert.AreEqual(expectedResult, ImageDataFactory.IsSupportedType(location));
using (FileStream inputStream = new FileStream(location.PathAndQuery, FileMode.Open, FileAccess.Read)) {
using (Stream inputStream = UrlUtil.OpenStream(location)) {
NUnit.Framework.Assert.AreEqual(expectedResult, ImageDataFactory.IsSupportedType(StreamUtil.InputStreamToArray
(inputStream)));
}
Expand Down
38 changes: 17 additions & 21 deletions itext.tests/itext.io.tests/itext/io/image/ImageTypeDetectorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ You should have received a copy of the GNU Affero General Public License
*/
using System;
using System.IO;
using iText.Commons.Utils;
using iText.IO.Util;
using iText.Test;

Expand Down Expand Up @@ -67,37 +68,32 @@ public virtual void TestNullUrl() {

[NUnit.Framework.Test]
public virtual void TestStreamUnknown() {
TestStream(new FileStream(SOURCE_FOLDER + IMAGE_NAME + ".txt", FileMode.Open, FileAccess.Read), ImageType.
NONE);
TestStream(FileUtil.GetInputStreamForFile(SOURCE_FOLDER + IMAGE_NAME + ".txt"), ImageType.NONE);
}

[NUnit.Framework.Test]
public virtual void TestStreamGif() {
TestStream(new FileStream(SOURCE_FOLDER + IMAGE_NAME + ".gif", FileMode.Open, FileAccess.Read), ImageType.
GIF);
TestStream(FileUtil.GetInputStreamForFile(SOURCE_FOLDER + IMAGE_NAME + ".gif"), ImageType.GIF);
}

[NUnit.Framework.Test]
public virtual void TestStreamJpeg() {
TestStream(new FileStream(SOURCE_FOLDER + IMAGE_NAME + ".jpg", FileMode.Open, FileAccess.Read), ImageType.
JPEG);
TestStream(FileUtil.GetInputStreamForFile(SOURCE_FOLDER + IMAGE_NAME + ".jpg"), ImageType.JPEG);
}

[NUnit.Framework.Test]
public virtual void TestStreamTiff() {
TestStream(new FileStream(SOURCE_FOLDER + IMAGE_NAME + ".tiff", FileMode.Open, FileAccess.Read), ImageType
.TIFF);
TestStream(FileUtil.GetInputStreamForFile(SOURCE_FOLDER + IMAGE_NAME + ".tiff"), ImageType.TIFF);
}

[NUnit.Framework.Test]
public virtual void TestStreamWmf() {
TestStream(new FileStream(SOURCE_FOLDER + IMAGE_NAME + ".wmf", FileMode.Open, FileAccess.Read), ImageType.
WMF);
TestStream(FileUtil.GetInputStreamForFile(SOURCE_FOLDER + IMAGE_NAME + ".wmf"), ImageType.WMF);
}

[NUnit.Framework.Test]
public virtual void TestStreamClosed() {
Stream stream = new FileStream(SOURCE_FOLDER + IMAGE_NAME + ".wmf", FileMode.Open, FileAccess.Read);
Stream stream = FileUtil.GetInputStreamForFile(SOURCE_FOLDER + IMAGE_NAME + ".wmf");
stream.Dispose();
// A common exception is expected instead of com.itextpdf.io.exceptions.IOException, because in .NET
// the thrown exception is different
Expand All @@ -106,32 +102,32 @@ public virtual void TestStreamClosed() {

[NUnit.Framework.Test]
public virtual void TestBytesUnknown() {
TestBytes(StreamUtil.InputStreamToArray(new FileStream(SOURCE_FOLDER + IMAGE_NAME + ".txt", FileMode.Open,
FileAccess.Read)), ImageType.NONE);
TestBytes(StreamUtil.InputStreamToArray(FileUtil.GetInputStreamForFile(SOURCE_FOLDER + IMAGE_NAME + ".txt"
)), ImageType.NONE);
}

[NUnit.Framework.Test]
public virtual void TestBytesGif() {
TestBytes(StreamUtil.InputStreamToArray(new FileStream(SOURCE_FOLDER + IMAGE_NAME + ".gif", FileMode.Open,
FileAccess.Read)), ImageType.GIF);
TestBytes(StreamUtil.InputStreamToArray(FileUtil.GetInputStreamForFile(SOURCE_FOLDER + IMAGE_NAME + ".gif"
)), ImageType.GIF);
}

[NUnit.Framework.Test]
public virtual void TestBytesJpeg() {
TestBytes(StreamUtil.InputStreamToArray(new FileStream(SOURCE_FOLDER + IMAGE_NAME + ".jpg", FileMode.Open,
FileAccess.Read)), ImageType.JPEG);
TestBytes(StreamUtil.InputStreamToArray(FileUtil.GetInputStreamForFile(SOURCE_FOLDER + IMAGE_NAME + ".jpg"
)), ImageType.JPEG);
}

[NUnit.Framework.Test]
public virtual void TestBytesTiff() {
TestBytes(StreamUtil.InputStreamToArray(new FileStream(SOURCE_FOLDER + IMAGE_NAME + ".tiff", FileMode.Open
, FileAccess.Read)), ImageType.TIFF);
TestBytes(StreamUtil.InputStreamToArray(FileUtil.GetInputStreamForFile(SOURCE_FOLDER + IMAGE_NAME + ".tiff"
)), ImageType.TIFF);
}

[NUnit.Framework.Test]
public virtual void TestBytesWmf() {
TestBytes(StreamUtil.InputStreamToArray(new FileStream(SOURCE_FOLDER + IMAGE_NAME + ".wmf", FileMode.Open,
FileAccess.Read)), ImageType.WMF);
TestBytes(StreamUtil.InputStreamToArray(FileUtil.GetInputStreamForFile(SOURCE_FOLDER + IMAGE_NAME + ".wmf"
)), ImageType.WMF);
}

private static void TestURL(Uri location, ImageType expectedType) {
Expand Down
Loading

0 comments on commit 4bcfd64

Please sign in to comment.